2.2  Numeric Representation in Unsigned Binary Number

  Unsigned binary numbers do not allow for the positive or negative signs.  To promote understanding, unsigned binary number may be conceptually converted to decimal numbers to express values.  Consider an eight-digit binary number as an example.
Since each digit of a binary number has a weight of 2, the least significant digit is 20, or 1, the next digit is 21, or 2, and still the next digit is 22, or 4. Thus, the weight doubles on each carry.  In converting an 8-bit binary number to a decimal number, assuming


we get 

Decimal representation =   

        a 7*27 + a 6*26 + a 5*25 + a 4*24 + a 3*23 + a 2*22 + a 1*21+ a 0*20

10110010 in binary, for example, is converted to a decimal equivalent as
        1*27 + 0*26 + 1*25 + 1*24 + 0*23 + 0*22 + 1*21 + 0*20
        = 128 + 32 + 16 + 2
        = 178
  All-one data "11111111" is the largest number that can be expressed in an 8-bit format.  It corresponds to 255 in decimal.  Eight-bit unsigned binary numbers can represent decimal numbers from 0 to 255. 
  Generally, N-bit unsigned binary numbers can represent the range of 
        0  to  2N-1

  Table 2.1 lists the lengths of unsigned binary numbers and the ranges they can represent.
 


Table 2.1  Ranges of unsigned binary numbers

Binary number length Range that can be represented
  4 digits   (4 bits)     0 to 15
  8 digits   (8 bits)     0 to 255
  16 digits (16 bits) 0 to 65,535
  32 digits (32 bits) 0 to 4,294,967,295


  Examples of addition of unsigned binary numbers are given below.  To their right are their decimal equivalents.
 
  01001010     74
+ 00111000   + 56
  10000000     130

 

and,
 
  10001001     173
+ 01111010   + 122
1 00000011     3

 

  This calculation, on the other hand, yields an incorrect result.  The resultant 9-bit value of 255 may appear correct, but the fact is that "calculating in 8-bit terms within the computer delivers a result in 8-bit terms only."  You can stretch or contract the length of a value as long as you work on its calculation on paper or in your brains, but not in the computer. You need to remember the length of arithmetic circuitry in the computer at all times.
  The addition of an extra digit to the length of a result is called a "carry."
 


Figure 2.2  Carry in a binary number

 
 

  Next, examples of subtraction of unsigned binary numbers are given below.  To their right are their decimal equivalents.

  10110101     181
- 10010111   - 151
  00011110     30

 

and,
 
  01001111     79
- 01010000   - 80
  11111111     255

 

  This calculation yields an incorrect result due to its failure to subtract a given value from a smaller value, where a 1 was leased from the ninth bit of the lower value.  This is called a "borrow."

  When a carry or borrow occurs in the course of a calculation in the computer, they are stored in status (in the H8/300H, the condition code).  When writing a program,  include a condition test instruction to define what specific action should be taken if a carry or borrow is encountered in the execution of a calculation instruction.
  Generally, no distinction is made between a carry and a borrow in the computer, but they are collectively called a "carry."