Two’s complement is the way most computers represent integers.  The highest bit indicates positive or negative:

0b0xxxxxxx = value is positive or zero

0b1xxxxxxx = value is negative

Convert positive value to negative

Invert the binary digits and add one to the result.

E.g. 1 / 0x01 becomes 0xFE, +1 = 0xFF

Convert negative value to positive

Invert the binary digits and add one to the result.

e.g. -1 / 0xFF  becomes 0x00, +1 = 0x01

Good resources

https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.