Binary Number System: Representations

Offset Signed Binary Integer

BITS

00000000
76543210
BBBBBBBB
where the representation is actually the value to be encoded plus some offset value, which depends on the final (fixed) length of the result. For example, for an 8-bit offset integer, the representation is done as follows.
Begin with the number to be encoded.
Add 127 to the number to be encoded.
Note: 127 is chosen because it is 2n-1-1 where n is the number
of bits in the final representation
The representation is now encoded as an 8-bit unsigned integer.
The examples, below, show how this technique would be used to represent -127, -85, 0, +42 and +127 in 8-bit offset:

                        value       
 value to               after 
 be encoded             offset      encoding
  
   -127     +  127   =      0   =   00000000
    -85     +  127   =     42   =   00101010
      0     +  127   =    127   =   01111111
    +42     +  127   =    169   =   10101001
   +128     +  127   =    255   =   11111111
Both sign-magnitude and offset representations have a significant limitation. They cannot be used reliably for mathematical manipulation. Consider, for example, the 8-bit sign-magnitude representations for +1 and -1. Clearly these two values should add up to zero, but they do not:
   00000001    =   +1 in sign-magnitude
+  10000001    =   -1 
 ----------
   10000010    =   -2 
According to this, +1 plus -1 equals -2. Wrong! Note that binary math works just like decimal math, but with fewer digits. In other words, all we need to remember is 0+0=0, 0+1=1, and 1+1=0, carry the 1.

Likewise, offset representations won't work:

   10000000    =   +1 in 127-offset
+  01111110    =   -1
 ----------
   11111110    = +127 
Again, we get silly answers: +1 plus -1 equals +127. A system of signed binary numbers must allow us to do binary math correctly. The following representation fits that requirement.

Next Page