home | 163 . 202 . 244 . 253 . 355 | courses | advisees | faq | honesty | jupiter files | schedule | webpage help | unix help | c++ help | vb help | assembly help

   signed binary numbers

Using the unsigned binary number system we know:
         1 is 2^0 = 1
        10 is 2^1 = 2 
       100 is 2^2 = 4
       ...
 1000 0000 is 2^7 = 128

The place values for n=8 bits UNSIGNED is:
    128    64    32    16     8     4     2     1
    ---    --    --    --     -     -     -     -
    2^7   2^6   2^5   2^4   2^3   2^2   2^1   2^0 
SO:   1     0     0     0     0     0     1     0 = 128 + 2 = 130

To express negative numbers, the scheme of the binary positional number system is simply changed slightly - with a large impact. Using n bits, the nth bit is simply changed from positive to negative. The place values for n=8 bits SIGNED is:
   -128    64    32    16     8     4     2     1
    ---    --    --    --     -     -     -     -
    2^7   2^6   2^5   2^4   2^3   2^2   2^1   2^0 
SO:   1     0     0     0     0     0     1     0 = -128 + 2 = -126

This scheme of representation is arrived at by taking the two's complement of a number - flipping the bits and adding one - as a way of negating the number.
   0000 1111 =  15 = 8 + 4 + 2 + 1     
   1111 0001 = -15 (flip all bits and add one)
   1111 0001 = -15 = -128 + 64 + 32 + 16 + 1

The high bit, (nth it) becomes the "sign bit" only because, if set, it indicates the number must be negative - it actually represents -2^(n-1).
Binary Decimal Unsigned Decimal Signed
a. 1111 1111 255 -1
b. 0000 0000 0 0
c. 1000 0000 128 -128
d. 0111 1111 127 127
e. 1000 0001 129 -127 (note: flip bits and add 1 from d. above)
f. 1000 1111 143 -113
g. 0000 1111 15 15
h. 1111 0001 241 -15 (note: flip bits and add 1 from g. above)

  n > 8 bits
  ==========
Nothing changes - an elegant scheme. 
If n = 16,
   32768 .. 128    64    32    16     8     4     2     1
   -----    ---    --    --    --     -     -     -     -
    2^15 .. 2^7   2^6   2^5   2^4   2^3   2^2   2^1   2^0 
SO:    1 ..   0     0     0     0     0     0     1     0 
       
           = -32768 + 2 = -32766
If n = 32, the nth bit (2^(n-1)) becomes 2,147,483,648
Interestingly, n '1' bits (111..111) is ALWAYS -1 decimal. Why?

Valid XHTML 1.0 Transitional