# What are two complement numbers

## Two's complement

The Two's complement is used for the binary representation of negative whole numbers.

### Explanation

1. First, the decimal number is converted into the corresponding binary number regardless of the minus sign. If the binary number begins with a "1", it must be preceded by a "0".

2. Then the complement is formed, i.e. a "1" becomes a "0" and vice versa.

3. Finally, a 1 is added to the complement.

### example

-9 in binary:

1. 9 as a binary number: 1001. Now a 0 is put in front: 01001

2. Complement: Off 01001 becomes 10110

3. Add 1: 10110 +1 = 10111

=> -9 = 10111

### Explanation

1. The first bit, also called the sign bit, has to be considered. If the first bit is set, i.e. 1, then it is a negative binary number. If it's not set, it's a positive binary number. Then steps 2 and 3 can be skipped.

2. Complement formation

4. Convert binary number to decimal number

5. If the sign bit of the original number was set, a minus sign must be placed in front of the decimal number.

### example

The number 10111 is to be converted.

1st sign bit set => It is a negative number.

2. Complement of 10111 is 01000

3. 01000 + 1 = 01001

4. 2^3+2^0 = 8 + 1 = 9

5. Set minus sign: -9