Two’s Complement

Two’s complement is a way to represent positive and negative integers in binary format. In order to convert a positive binary number to the two’s complement negative number, you invert the bits and add 1.

Let’s say we have an 8-bit integer ‘00001000’ representing 8. We would get ‘11110111’ and then ‘11111000’ when we add the 1. The advantage of using two’s complement is that we can use regular math with the two’s complement version of the negative number. If we were to add 8, to ‘11111000’, the most significant number would overflow and we would go back to ‘00000000’. The two’s complement has a 1 at the most significant bit and accounts for half of the range.