Computers have limited memory that is divided into words. Each number (integer) that is going to be represented in the computer needs to fit into a word. This means that the size of the number to be represented is restricted. For example, if a word is 32 bits, then the largest number that can be stored in one word would be at most 32 bits long. This works out to numbers up to about 4.5 billion (i.e. 2^32). This is complicated by the fact that you want to represent negative numbers.

The naive approach to negative numbers would to stick a bit at the end of the number to indicate positive or negative. In other words, 00001001 would be positive nine and 10001001 would be negative nine. You can see that this extra bit restricts the size of the largest positive number to 2^31 (assuming 32 bit words still). You’re going to get this problem, no matter what your representation of negative numbers is… You can think of the word in memory as your information bank. You can store 32 bits of information and the information about negativeness will always be at least one bit.

The real problem with this approach is that it results in very complicated arithmetic for the computer. How do you add -9 and +9? The algorithm, as written in primitive assembly, to do this would be very complex (i.e. look at the last digit, do this if its 1 and do that if its negative, etc, etc).

To simplify the math, the ‘ones compliment’ approach was taken to represent negative numbers. The idea is to invert all the bits for negative numbers. Negative nine would be 11110110. Again, the first digit represents the sign but the arithmetic becomes much easier. The problem with this method is that you get two zeros… positive and negative zero (i.e. 11111111 and 00000000). You’d be stuck writing special cases in all your software for each of these zeros. So then one’s compliment is inadequate.

The approach in response to the short comings of one’s compliment, the one that is used by most computers today, is two’s compliment. Basically, it’s the same as one’s compliment but you add one to the result of flipping the bits. This eliminates the extra zero (i.e. 00000001 plus 11111111 is just 00000000 so negative and positive zero have the same representation). This method also allows for simple arithmatatic.

### Like this:

Like Loading...

*Related*

## 0 Responses to “Binary representation”