Page 94 - Bebop to The Boolean Boogie An Unconventional Guide to Electronics Fundamentals, Components, and Processes
P. 94

Binary Arithmetic    75


               'Unfortunately, all of the previous examples will return incorrect results if
           a larger value is subtracted from a smaller value; that is, for these techniques
           to work, the final result must be greater than or equal to zero. In the case of
           unsigned binary numbers, the reason is clear because, by definition, an
           unsigned binary number can only be used to represent a positive value, but
           subtracting a larger value from a smaller value results in a negative value. It
           would obviously be somewhat inconvenient if computers could only be used to
           generate positive values, so we need some way to represent negative numbers.

           Signed Binary Numbers
               Signed binary numbers can be used to represent both positive and negative
           values, and they do this in a rather cunning way. In standard decimal
           arithmetic, negative numbers are typically represented in a form known
           as ~ign-magnitude,~ which means prefixing values with plus or minus signs,
           For example, values of plus and minus twenty-seven would be shown as +27
           and -27,  respectively. However, for reasons of efficiency, computers rarely
           employ the sign-magnitude form, and instead use the signed binary format, in
           which the most significant bit is also called the sign bit (Figure 8-8).
               The least significant bits continue to represent the same positive quantities
           as for unsigned binary numbers, but the sign bit is used to represent a negative
           quantity. In the case of a signed 8-bit number, a 1 in the sign bit represents -27
           = -128,  and the rernaining bits are used to represent positive values in the range
           O,,  chrough +127,,.  Thus, when the value represented by the sign bit is corn-
           bined with the values represented by the remaining bits, an 8-bit signed binary
           number can be used to represent values in the range -l28,,  through +1271,.
               To illustrate the differences between the sign-magnitude and signed binary
           formats, first consider a positive sign-magnitude decimal number and its negative
           equivalent: for example, +27 and -27.  As we see, the digits are identical for
           both cases and only the sign changes. Now consider the same values represented
           as signed binary numbers (Figure 8-9).
               In this case, the bit patterns of the two binary numbers are very different.
           This is because the sign bit represents an actual quantity (-12810) rather than
           a simple plus or minus; rhus, the signed equivalent of -2710  is formed by com-
           bining -128,,  with ~101,~. Now pay attention because this is the clever part:


           3 Sometimes written as sign+rnugnitude.
   89   90   91   92   93   94   95   96   97   98   99