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 integersThe 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 attemptThe 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 attemptHowever, 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 2By 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 2By 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 attemptDone! 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 integersIf 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.
- Omnipotent or omniscient which and why
- How successful is a tumor removal operation
- What is the best Swift Unit Testing Framework
- What is Benedict Cumberbatch famous for
- Why shouldn't margarine be used in cooking?
- What do hedge funds celebrate
- How big do Morgan horses normally get?
- How can I become a smart speaker
- Will influencer marketing replace advertising
- What is waste separation
- How can I lose weight with arthritis
- What are some alternative uses for WD40
- Who created Prog Rock
- Which chain restaurant serves the best fries?
- Why has Facebook not yet held a public listing
- What are some examples of GIS
- What is cross-price elasticity
- Is biscuit thicker than soup
- Why is the Account Management Tool so important
- Does the pea soup have protein
- Phenol shows the Friedel Crafts reaction
- Why would you like to thank Google
- Who is Utah's Worst Enemy
- Will a libertarian ever become president