Data Representation
1. Number Conversions
At A-Level, you must be fast and accurate when moving between bases. A common trick is using Hexadecimal as a "bridge" between Denary and Binary.
Binary to Hex
Split the binary number into nibbles (4 bits) from right to left.
1011 | 010111(B) | 5 ➔ B516
Denary to Hex
Divide by 16 repeatedly and track the remainders.
157 / 16 = 9 r 13(D)9 / 16 = 0 r 9 ➔ 9D16
2. Signed Numbers & Two's Complement
Standard binary only represents positive numbers (Unsigned). To represent Negative Numbers, we use Two's Complement.
The Method (Example: Represent -5 in 8-bit)
1. Find positive 5 in binary:
0000 0101
2. Flip all bits (One's Complement):
1111 1010
3. Add 1 to the result:
1111 1011 (This is -5)
0000 0101
2. Flip all bits (One's Complement):
1111 1010
3. Add 1 to the result:
1111 1011 (This is -5)
Sign Bit: In Two's Complement, the Most Significant Bit (MSB) acts as the sign. If MSB is 1, the number is negative. If 0, it is positive.
3. Binary Coded Decimal (BCD)
BCD is a system where each individual digit of a denary number is represented by its own 4-bit binary code (nibble).
Example: Convert 395 to BCD
- Digit 3 ➔ 0011
- Digit 9 ➔ 1001
- Digit 5 ➔ 0101
Result: 0011 1001 0101
Why use BCD?
- Decimal Displays: Used in electronic scales, digital clocks, and calculators where each digit is displayed separately.
- Financial Accuracy: Avoids rounding errors that can occur when converting large fractions into pure binary.
4. Comparison Summary
| Type | Representation | Key Feature |
|---|---|---|
| Unsigned | 0 to 255 (8-bit) | Only positive values. |
| Signed | -128 to +127 (8-bit) | Uses Two's Complement for negatives. |
| BCD | Digit by Digit | Exact decimal representation. |
⚠️ A-Level Hint: In 8-bit Two's Complement, the range is $-2^{7}$ to $2^{7}-1$. If you try to calculate a number outside this (like 130), you will encounter Overflow.