Mastering O Level Computer Science
Data Representation Systems
Beyond Binary
Computers operate on binary, but long strings of 1s and 0s are cumbersome for people to read and write. To make things simpler, we often use other number systems to represent binary data more compactly. One of the most common is hexadecimal.
Hexadecimal, or 'hex', is a base-16 number system. This means it uses sixteen distinct symbols to represent values. It uses the familiar digits 0 through 9, and then adds the letters A through F to represent the values 10 through 15. The key reason hex is so useful in computing is that one hexadecimal digit can represent exactly four binary digits (a nibble). This makes conversion between the two systems incredibly straightforward.
| Denary | Hexadecimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| 10 | A | 1010 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
Converting Between Systems
Being able to convert between denary, binary, and hexadecimal is a fundamental skill. To convert a hexadecimal number to denary, you multiply each digit by a power of 16. The rightmost digit is multiplied by $16^0$ (which is 1), the next digit to the left is multiplied by $16^1$ (which is 16), and so on. Then, you simply add the results together.
Converting from hexadecimal to binary is even easier. You just replace each hexadecimal digit with its 4-bit binary equivalent from the table above. It’s a direct substitution.
Hex in the Wild
Hexadecimal isn't just an academic exercise; it's used everywhere in computing. One key application is in networking. Every device that connects to a network has a unique identifier burned into its hardware called a MAC address. This address is typically represented as six pairs of hexadecimal digits, like 00:1A:2B:3C:4D:5E.
You also see hexadecimal used extensively in web design and graphics to define colours. Colours on a screen are created by mixing different intensities of red, green, and blue light. An uses a six-digit hex code to specify the intensity of each of these three primary colours. For example, #FFFFFF is pure white (maximum intensity for all three colours), while #FF0000 is pure red.
Binary Operations
At the lowest level, a computer's processor is performing mathematical operations on binary numbers. Binary addition follows the same principles as denary addition, but the rules are simpler. You add column by column from right to left, carrying over when a sum exceeds 1.
The rules are: $0 + 0 = 0$ $0 + 1 = 1$ $1 + 0 = 1$ $1 + 1 = 0$, carry 1 $1 + 1 + 1 = 1$, carry 1
Computer processors work with a fixed number of bits, often stored in an 8-bit register. This limitation can cause a problem called an . This occurs when the result of a calculation is too large to fit into the available number of bits. For example, if you add two 8-bit numbers and the result requires a 9th bit, the 9th bit is typically discarded, leading to an incorrect result.
Signed Integers and Shifts
So far we've only dealt with positive numbers. To represent negative numbers in binary, computers often use a method called . In an 8-bit two's complement system, the most significant bit (the leftmost bit) indicates the sign. A '0' means the number is positive, and a '1' means it's negative. This system makes arithmetic with negative numbers much simpler for the processor's circuitry.
| Denary | Two's Complement (8-bit) |
|---|---|
| 3 | 00000011 |
| -3 | 11111101 |
| 127 | 01111111 |
| -128 | 10000000 |
Finally, processors can perform a very fast type of multiplication and division using logical binary shifts. A logical left shift moves every bit one position to the left, and a 0 is added to the rightmost position. This is equivalent to multiplying the number by 2. Shifting left twice multiplies by 4, and so on.
A logical right shift moves every bit one position to the right, and a 0 is added to the leftmost position. This is equivalent to performing an integer division by 2.
Why is the hexadecimal number system frequently used in computing?
What is the denary (base-10) equivalent of the hexadecimal number 2B?
