ССЫЛКА: https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html
Я инвертирую все биты и добавляю 1. Программно:
// in C++11
int _powers[] = {
1,
2,
4,
8,
16,
32,
64,
128
};
int value=3;
int n_bits=4;
int twos_complement = (value ^ ( _powers[n_bits]-1)) + 1;