Two's complement calculator
To negate a number in two’s complement, flip every bit and add one. 42 is 00101010, inverted is 11010101, plus one gives 11010110 — which is −42. The reason this works is that it makes addition identical for signed and unsigned values, so a processor needs only one adder circuit rather than two. That single design economy is why two’s complement won over the alternatives.
Two's complement represents negatives by flipping every bit and adding one. In 8 bits, −42 is 11010110, which reads as 214 unsigned. The signed range for 8 bits is −128 to 127.
How to read two's complement
The asymmetry of the range trips people up: 8 bits hold −128 to 127, one more negative than positive. That is because zero takes up a slot on the positive side, and it means negating the most negative value overflows — the negative of −128 in 8 bits is still −128. It is a genuine edge case that has caused real bugs, most famously in code that takes the absolute value of an integer without checking for it.
Questions
Invert every bit of the positive value and add one.