computer representation of integers
Computer systems that use a hardware binary representation for integral values typically have one of two choices available to them for the representation of negative integers: one’s complement or two’s complement.
Generally the high-order bit of a binary representation is used as a sign bit. If the value is , then the number is negative, while if the value is , the number is nonnegative.
In a computer that uses one’s complement notation, the representation of a negative number is the one’s complement of the representation of a positive number. In other words, the negation of an integer can be accomplished by exclusive or’ing its value with a word consisting of all 1’s. So, in one’s complement, assuming a 4-bit word for compactness,
Two’s complement, as its name implies, represents negative integers by taking their complement with respect to the next higher power of . Thus, in a -bit world, the negative of a value is found by subtracting it from (as a bit string). Thus, for example, , so .
An unfortunate result of using one’s complement notation is that zero has two distinct representations:
Two’s complement fixes this, since , which gets truncated in 4 bits to . However, it introduces an asymmetry in the representational range. While a -bit one’s complement number can represent any integer from to , a -bit two’s complement number can represent integers from to , being represented by the value .
In addition, two’s complement is in some sense more natural than one’s complement since if you regard the representation as an unsigned number, its value modulo is in fact the value it represents. In other words, for example, consider again a -bit word size. Then the representation of in two’s complement is . Thinking of as an unsigned number, its value is , which is in fact .
This fact means that multiplication of two’s complement representations is quite easy - one need only multiply the bit patterns together as if they were unsigned, and consider the rightmost bits of the result (thus taking the result modulo the word size).
Using one’s complement notation, no such simple algorithm is possible. Thus, for example, in one’s complement one has
yet mutiplying the unsigned values and truncating results in , or .
This inefficiency in required multiplication algorithms, together with the obvious problem of having multiple representations of zero, has led to the almost complete abandonment of one’s complement notation today.
|Title||computer representation of integers|
|Date of creation||2013-03-22 16:55:55|
|Last modified on||2013-03-22 16:55:55|
|Last modified by||rm50 (10146)|