What is negative 1 in binary

Negative binary numbers

back | further

Introduction value range / negative integers

Of course, we can't just put a minus sign in front of a dual number; that would take up storage space again. Since we only want to store the information 0 and 1, we have the option of marking with a 0 or 1 whether we are interpreting a number positively or negatively. We have already dealt with the formation of complements in the subtraction part. We develop the negative numbers in three steps.

Positive integers

The previous considerations allow us to represent only positive integers. The smallest number is 0, the largest number depends on the amount of memory available. So far we have limited ourselves to one byte. Usually, depending on the programming language, several bytes are combined into one memory location. Typically this is two or four bytes. This means that the largest representable decimal numbers are then 65535 or 4294967295.

Negative integers - 1st attempt

The next step now is to introduce negative numbers. This seems pretty easy, but it is quite difficult. I will explain the negative numbers in three steps. Please read at least until the third attempt, because only then will the "correct" negative numbers be described.
For the sake of simplicity, we again limit ourselves to one byte. Of course, the principle can again be transferred to several bytes as a memory area.
We simply mark negative numbers with a leading bit. These bits are sometimes called "flags".
1 = 00000001 then becomes -1 = 10000001.
17 = 00010001 then becomes -17 = 10010001.

Negative integers - 2nd attempt

However, version 1 of the negative integers has one major disadvantage. With the positive integers, I get the next larger number by adding 1. Once I have reached the maximum number, adding 1 through the overflow means that I come back to the lower end (see chapter "Caution overflow"). In the case of negative numbers according to version 1, however, the addition of 1 does not - mathematically correct - lead to the larger number, but to the smaller one. Example: 10000001 + 00000001 = 10000010 this is mathematically incorrect, because in decimal notation there is -1 + 1 = -2 !!! For this reason, negative numbers are not only represented by the identification with the first bit, but the complement formation already introduced above is used for this.

The one's complement - part 2

By forming the one's complement, our range of values ​​suddenly has two zeros, namely 00000000 and 11111111. If I add 1 = 00000001 to -1 = 11111110, I get 11111111. That means. we still have a logical flaw in our deliberations. We correct this mistake by forming the two's complement. The two's complement of zero then results in zero again. 00000000 becomes 11111111 in the one's complement and through the addition of 00000001 and the overflow again to 00000000.

The two's complement - part 2

By forming the one's complement, our range of values ​​suddenly has two zeros, namely 00000000 and 11111111. If I add 1 = 00000001 to -1 = 11111110, I get 11111111. That means. we still have a logical flaw in our deliberations. We correct this mistake by forming the two's complement. The two's complement of zero then results in zero again. 00000000 becomes 11111111 in the one's complement and through the addition of 00000001 and the overflow again to 00000000.

Negative integers - 3rd attempt

Done! The negative numbers are represented by forming the two's complement. Here some examples:
1 = 00000001 becomes -1 = 11111111
5 = 00000101 becomes -5 = 11111011
17 = 00010001 becomes -17 = 11101111
So I can still tell from the first bit whether a number is negative or positive.

Range of negative integers

If I take a byte as a memory limit, I get the following interesting numbers
00000000 = 0
01111111 = 127
10000000 = -128
My previous range of values ​​from 0 to 255 changes to -128 to +127. Again, I have a total of 256 different numbers. Our interpretation of the numbers is changing.