# Вопрос по – Что такое «Дополнение 2»?

Error: User Rate Limit ExceededstrugglingError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded.

Error: User Rate Limit Exceeded**community wiki**Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded**a clear and concise definition**Error: User Rate Limit Exceeded

It is a useful convention. The same circuits and logic operations that add / subtract positive numbers in binary still work on both positive and negative numbers if using the convention, that's why it's so useful and omnipresent.

Imagine the odometer of a car, it rolls around at (say) 99999. If you increment 00000 you get 00001. If you decrement 00000, you get 99999 (due to the roll-around). If you add one back to 99999 it goes back to 00000. So it's useful to decide that 99999 represents -1. Likewise, it is very useful to decide that 99998 represents -2, and so on. You have to stop somewhere, and also by convention, the top half of the numbers are deemed to be negative (50000-99999), and the bottom half positive just stand for themselves (00000-49999). As a result, the top digit being 5-9 means the represented number is negative, and it being 0-4 means the represented is positive - exactly the same as the top bit representing sign in a two's complement binary number.

Understanding this was hard for me too. Once I got it and went back to re-read the books articles and explanations (there was no internet back then), it turned out a lot of those describing it didn't really understand it. I did write a book teaching assembly language after that (which did sell quite well for 10 years).

```
0000 = 0
0001 = 1
0010 = 2
...
1111 = 15
```

Sign Magnitude and Excess Notation
```
0000 = +0
0001 = +1
0010 = +2
...
1000 = -0
1001 = -1
1111 = -7
```

```
0010
1001 +
----
```

?

Convert Decimal to Two's ComplementConvert the number to binary (ignore the sign for now) e.g. 5 is 0101 and -5 is 0101

If the number is a positive number then you are done. e.g. 5 is 0101 in binary using twos complement notation.

If the number is negative then

3.1 find the complement (invert 0's and 1's) e.g. -5 is 0101 so finding the complement is 1010

3.2 Add 1 to the complement 1010 + 1 = 1011. Therefore, -5 in two's complement is 1011.

```
2 = 0010
-3 = 1101 +
-------------
-1 = 1111
```

Converting Two's Complement to Decimal
The number starts with 1, so it's negative, so we find the complement of 1111, which is 0000.

Add 1 to 0000, and we obtain 0001.

Convert 0001 to decimal, which is 1.

Apply the sign = -1.

Error: User Rate Limit ExceededError: User Rate Limit Exceeded this article explain it graphically.

`0000`

- zero
`0001`

- one
`0010`

- two
`0011`

- three
`0100`

to `0111`

- four to seven
3-1 = 7.

`1111`

- negative one
`1110`

- negative two
`1101`

- negative three
`1100`

to `1000`

- negative four to negative eight
**Distinguishing between positive and negative numbers**

`1`

`0`

`1000`

Error: User Rate Limit Exceeded

```
00
01
02
..
```

Error: User Rate Limit Exceeded

```
98
99
00
```

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded99.

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded**ten's complement**Error: User Rate Limit Exceeded**two's complement**Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededjust worksError: User Rate Limit Exceeded