Hexadecimal Numbers (OCR A-Level Computer Science): Revision Notes
Hexadecimal Numbers
Overview
Hexadecimal (or "hex") is a base-16 number system that uses sixteen symbols: 0–9 and A–F. In computing, hexadecimal is often preferred for representing binary data in a more readable format, as it is compact and easy to interpret. Understanding hexadecimal notation and converting between hex, binary, and decimal (denary) is essential, as hex is widely used in memory addresses, colour codes, and low-level programming.
Hexadecimal System
- Base-16 Representation: Hexadecimal uses sixteen symbols:
- 0 to 9 represent values 0 to 9.
- A to F represent values 10 to 15.
- Compact Form: Each hexadecimal digit represents four binary bits (a nibble). This allows large binary numbers to be represented with fewer characters, making hex both compact and more human-readable.
Example: The hexadecimal number 2F is equivalent to 0010 1111 in binary.
Benefits of Hexadecimal Over Binary
- Readability: Hexadecimal is easier for humans to read and write than long binary sequences.
- Compact Representation: Four binary bits are represented by one hex digit, making hex notation shorter.
- Common Uses:
- Memory Addresses: Hex is often used to represent memory locations in computing.
- Colour Codes: Web colours are represented in hex (e.g., #FF5733).
- Assembly Language and Machine Code: Hexadecimal provides an easier-to-read representation of binary-coded machine instructions.
Conversion Processes
Converting Between Binary and Hexadecimal
Binary to Hexadecimal
- Split the binary number into groups of four bits (starting from the right).
- Convert each group to its corresponding hex digit.
Example: Convert 11010110 to hexadecimal.
- Group into nibbles: 1101 0110
- Convert each nibble: 1101 = D, 0110 = 6
Result: D6
Hexadecimal to Binary
Replace each hex digit with its four-bit binary equivalent.
Example: Convert 3B to binary.
- 3 in hex = 0011 in binary
- B in hex = 1011 in binary
Result: 00111011
Converting Between Decimal (Denary) and Hexadecimal
Decimal to Hexadecimal
- Repeatedly divide the decimal number by 16, recording the remainders.
- Write down the remainders in reverse order to get the hex representation.
Example: Convert 254 to hexadecimal.
- remainder 14 (E)
- remainder 15 (F)
Result: FE
Hexadecimal to Decimal
Multiply each hex digit by its positional value (powers of 16) and sum the results.
Example: Convert 4A to decimal.
- 4 in the place =
- A (which is 10) in the place =
- Sum: 64 + 10 = 74
Result: 74
Examples
Example 1: Binary to Hexadecimal Convert 11101100 to hexadecimal.
- Split into nibbles: 1110 1100
- Convert each nibble: 1110 = E, 1100 = C
Result: EC
Example 2: Hexadecimal to Binary Convert 5A to binary.
- 5 in hex = 0101 in binary
- A (10) in hex = 1010 in binary
Result: 01011010
Example 3: Decimal to Hexadecimal Convert 345 to hexadecimal.
- remainder 9
- remainder 5
Result: 159
Example 4: Hexadecimal to Decimal Convert 7F to decimal.
- 7 in the place =
- F (15) in the place =
- Sum: 112 + 15 = 127
Result: 127
Note Summary
Common Mistakes
- Grouping Errors in Binary-Hex Conversion: Forgetting to start grouping from the right when converting binary to hex.
- Incorrect Remainder Order in Decimal to Hex Conversion: Reversing the order of remainders incorrectly.
- Confusing Hex Values for Decimal Values: Misinterpreting letters in hex (e.g., treating A as 1 rather than 10).
Key Takeaways
- Hexadecimal (Base-16): A compact, human-readable format, with values ranging from 0–9 and A–F.
- Conversion Skills:
- Binary to Hex: Group into nibbles, and convert each to a hex digit.
- Decimal to Hex: Use division by 16, reverse remainders.
- Hex to Decimal: Multiply each digit by powers of 16 and sum.
- Practical Uses: Hex is commonly used for readability in computing contexts like memory addresses, colours, and machine code.