Representing numbers requires grouping collections of bits and understanding the rules to interpret the collection of bits. The term “representation” is used to describe the system and rules for how bits are interpreted within the number representation.
A common starting point is unsigned numbers. An unsigned number is a collection of N bits that represents the integer from 0 to (2N-1). For example if N=8, the values that can be represented are 0, 1,…,255. As implied by the name, unsigned number representation does not include negative numbers and negative numbers cannot be expressed. In addition, unsigned numbers are integers only with the range limited by the number of bits. Fractional quantities and common constants such as π cannot be expressed either.
To help with the subsequent discussions, the following notations will be used:
| Symbol | Meaning |
|---|---|
| B | unsigned binary number |
| N | number of bits in an unsigned binary number |
| bi | i ∈ [0,1,…,(2N-1)] is the ith bit in binary number B |
| VB | value of unsigned binary number B |
With the above notation, assuming N=8, the value of a binary number B is expressed as
VB = (b7×27) + (b6×26) + (b5×25) + (b4×24) + (b3×23) + (b2×22) + (b1×21) + (b0×20)
Note that this is similar to the place-value notation for decimal numbers. This is no mistake, because this expresses the value of the binary number B in place-value in binary. The most significant bit is the left most bit, b7, and contributes the most weight to the value when it is 1. The least significant bit is b0 and can contribute one to the value.
If B=”11001010″, then
VB = (1×27) + (1×26) + (0×25) + (0×24) + (1×23) + (0×22) + (1×21) + (0×20)
| VB | = (1×27) + (1×26) + (0×25) + (0×24) + (1×23) + (0×22) + (1×21) + (0×20) |
| = 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 | |
| = 202 |
Next, we need a way to express a decimal value in binary. A commonly used method is to divide the value by 2 with the quotient being carried forward and the remainder being the next bit in the binary number (least significant bit first). The process is repeated on the quotient for the next most significant bit until a quotient of zero occurs. Here is the process for converting 202 to binary:
| Value | Quotient | Remainder | Bit |
|---|---|---|---|
| 202 | 101 | 0 | b0 |
| 101 | 50 | 1 | b1 |
| 50 | 25 | 0 | b2 |
| 25 | 12 | 1 | b3 |
| 12 | 6 | 0 | b4 |
| 6 | 3 | 0 | b5 |
| 3 | 1 | 1 | b6 |
| 1 | 0 | 1 | b7 |
Reforming the bits into the binary number results in B=”11001010″. Note that the bits are written in an order that is reversed compared with the order they are generated.