Number Systems
The 0s and 1s present in the logic circuits discussed in the course can be used to represent real data inside logic circuitry in, for example, microprocessors. To do this a binary format has to be adopted.
The usual practise is to use so-called pure binary coding whereby each binary digit (either 0 or 1) carries a certain weight according to its position in the binary number. So, for example
| 110100 | = | 1x25 | + | 1x24 | + | 0x23 | + | 1x22 | + | 0x21 | + | 0x20 |
| = | 32 | + | 16 | + | 0 | + | 4 | + | 0 | + | 0 | |
| = | 52 |
The same approach applies to non-integral numbers so, for example
| 110.101 | = | 1x22 | + | 1x21 | + | 0x20 | + | 1x2-1 | + | 0x2-2 | + | 1x2-3 |
| = | 4 | + | 2 | + | 0 | + | 0.5 | + | 0 | + | 0.125 | |
| = | 6.625 |
These examples illustrate binary to decimal conversion. To convert a fractional decimal number to binary then the procedure to follow is
- first divide the number at the decimal point and treat the two parts separately.
- For the integer part then repeatedly divide it by 2 and store the remainder until nothing is left.
- The remainders when reverse-ordered gives the first part of the binary number. The reverse-ordering comes about since the first division by 2 gives the least significant bit (lsb) and so on until the last division which gives the most significant bit (msb).
- For the fractional part repeatedly multiply by 2 and record the carries i.e. when the resulting number is greater than 1. Repeat this process until the desired precision is achieved.
A useful way of expressing long pure binary coded numbers is by the use of hexadecimal numbers i.e. base 16. This is because each group of four bits (called a nibble since 2 nibbles make a byte!) can be converted into one hexadecimal number. The mapping between binary, decimal and hexadecimal (hex.) numbers is shown below.
| Decimal | Binary | Hex | Decimal | Binary | Hex |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | 10 | 1010 | A |
| 3 | 0011 | 3 | 11 | 1011 | B |
| 4 | 0100 | 4 | 12 | 1100 | C |
| 5 | 0101 | 5 | 13 | 1101 | D |
| 6 | 0110 | 6 | 14 | 1110 | E |
| 7 | 0111 | 7 | 15 | 1111 | F |
To convert a binary number into its hexadecimal equivalent first ensure that the binary number has a number of digits that is a multiple of 4, if not add zeros to the left hand side of the number until it does. Then split the number into nibbles and convert each nibble into its hexadecimal counterpart.
An example of binary to hexadecimal conversion can be found in the Solved Problems.