2's Complement

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*Several options exist for the representation of signed integer values as binary numbers:
 
*1's Complement: A negative number is represented by changing all zeroes to ones and all ones to zeroes. Example for an 8 bit representation of 1 and -1:


BinarySignedUnsigned

0000 000111
1111 1110-1254

Supported Range: -127 to 127. Disadvantage: We have two representations for 0: 0000 0000 and 1111 1111.


 

*2's Complement: Similar to 1's complement but adding 1 for negative numbers:


BinarySignedUnsigned

0000 000111
1111 1111-1255
0111 1111127127
1000 0001-127129
1000 0000-128128

Supported Range: -128 to 127. Disadvantage: There is no corresponding positive number to the smallest negative integer value.
 

*Java, the JVM, and all modern processor architectures use 2's complement.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002