Data Representation (Copy)
Cheat Sheet: A Level Computer Science – Number Systems, Representations & Encodings
1. Binary Magnitudes and Prefixes
Binary vs Decimal Prefixes
| Prefix | Decimal (Base 10) | Binary (Base 2) |
|---|---|---|
| kilo (k) | 10³ = 1,000 | kibi (Ki) = 2¹⁰ = 1,024 |
| mega (M) | 10⁶ = 1,000,000 | mebi (Mi) = 2²⁰ = 1,048,576 |
| giga (G) | 10⁹ = 1,000,000,000 | gibi (Gi) = 2³⁰ = 1,073,741,824 |
| tera (T) | 10¹² = 1,000,000,000,000 | tebi (Ti) = 2⁴⁰ = 1,099,511,627,776 |
- Use: Decimal prefixes often used for storage capacity (e.g. hard drives), while binary prefixes are used in memory size (e.g. RAM).
2. Number Systems
Bases
- Binary (Base 2): Only digits 0 and 1
- Denary/Decimal (Base 10): Digits 0–9
- Hexadecimal (Base 16): Digits 0–9 and letters A–F
- BCD (Binary Coded Decimal): Each digit of a denary number is represented separately in 4-bit binary
3. Conversions Between Number Bases
Binary ↔ Decimal
- Binary to Decimal: Multiply each bit by 2ⁿ (n = position from right, starting at 0), then add.
- Decimal to Binary: Divide by 2 repeatedly, record remainders, read bottom to top.
Hexadecimal ↔ Decimal
- Hex to Decimal: Convert each digit using hex values and multiply by powers of 16.
- Decimal to Hex: Divide by 16 repeatedly, record remainders, convert to hex digits.
Binary ↔ Hexadecimal
- Group binary in 4s (from right), convert each group to one hex digit.
Decimal ↔ BCD
- Convert each decimal digit into its 4-bit binary form separately.
4. One’s and Two’s Complement
One’s Complement
- Flip all bits (0 ↔ 1)
- Used to represent negative numbers
Two’s Complement
- Take one’s complement and add 1
- Allows representation of both positive and negative integers
- Range for 8-bit two’s complement: -128 to +127
5. Binary Addition and Subtraction
Binary Addition Rules
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (carry 1)
Binary Subtraction Using Two’s Complement
- Convert subtrahend to two’s complement
- Add to the minuend
- If overflow bit, ignore it (only when operands have different signs)
6. Overflow in Binary
- Occurs when: Result > max representable number in fixed number of bits
- E.g. adding two 8-bit numbers resulting in a 9-bit answer
7. Practical Applications of BCD and Hexadecimal
BCD Applications
- Used in digital clocks, calculators, and financial systems where exact decimal representation is needed
Hexadecimal Applications
- Color codes in web design (e.g., #FF5733)
- Memory addressing and debugging (compact and easy to read vs long binary)
8. Internal Binary Representation of Character Data
ASCII (7-bit)
- Represents 128 characters (including control codes and standard English characters)
- E.g., A = 65 = 01000001
Extended ASCII (8-bit)
- 256 characters – adds symbols and foreign language characters
Unicode
- Supports 1.1+ million characters
- Encodes characters from almost all written languages
- UTF-8 (variable length), UTF-16, UTF-32 are common encoding formats
Important Notes
- Character set: A defined list of characters recognized by the computer system with a corresponding binary code
- You do not need to memorize the binary for each character (e.g., A = 01000001), just understand how encoding works
Let me know when you’re ready for the next topic.
