๐Ÿ“‘ Contents
โ˜…

Chapter 1.1: Data Representation

AS Level Computer Science (9618)

๐Ÿ“š Learning Objectives

1. Number Systems Overview

A number system is a way of representing amounts or quantities using a specific set of symbols and rules. Computers use different number systems to process and store data efficiently.

1.1 Denary (Decimal) Number System

The number system we use in everyday life is called denary (or decimal). It has a base of 10 because it uses 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each position represents a power of 10.

1000s 100s 10s 1s (10ยณ) (10ยฒ) (10ยน) (10โฐ) 3 2 6 8 3ร—1000 + 2ร—100 + 6ร—10 + 8ร—1 = 3268

1.2 Binary Number System

The binary number system uses only two digits: 0 and 1. It has a base of 2. Each position represents a power of 2. This is the fundamental language of computers because electronic circuits can easily represent two states: ON (1) and OFF (0).

128 64 32 16 8 4 2 1 2โท 2โถ 2โต 2โด 2ยณ 2ยฒ 2ยน 2โฐ 0 1 1 0 1 0 0 1 64 + 32 + 8 + 1 = 105 (denary)
โš ๏ธ Important Terms

1.3 Hexadecimal Number System

The hexadecimal (hex) number system uses 16 symbols: digits 0-9 and letters A-F. It has a base of 16. Hex is widely used in computing because it provides a more compact way to represent binary values.

Denary 01234567
Hex 01234567
Denary 89101112131415
Hex 89ABCDEF

2. Denary โ†” Binary Conversions

2.1 Denary to Binary Conversion

There are two main methods to convert denary numbers to binary. Choose the one that works best for you!

๐Ÿ“ Method 1: Repeated Division by 2

This method involves repeatedly dividing by 2 and recording remainders.

  1. Divide the denary number by 2
  2. Record the remainder (0 or 1)
  3. Use the quotient (answer) as the new number
  4. Repeat until the quotient is 0
  5. Read remainders from BOTTOM to TOP
Example: Convert 173 to Binary 173 รท 2 = 86 remainder 1 โ†‘ 86 รท 2 = 43 remainder 0 โ†‘ 43 รท 2 = 21 remainder 1 โ†‘ 21 รท 2 = 10 remainder 1 โ†‘ 10 รท 2 = 5 remainder 0 โ†‘ 5 รท 2 = 2 remainder 1 โ†‘ 2 รท 2 = 1 remainder 0 โ†‘ 1 รท 2 = 0 remainder 1 โ†‘ Read bottom โ†’ top: 10101101โ‚‚ = 173โ‚โ‚€
๐Ÿ“ Method 2: Positional Value Method (Subtraction)

This method subtracts the largest possible powers of 2 from the number.

  1. Write down the powers of 2: 128, 64, 32, 16, 8, 4, 2, 1
  2. Find the largest power that fits into your number
  3. Put a 1 under that power, subtract it from your number
  4. Continue until the remainder is 0
  5. Put 0 under any unused powers
Example: Convert 156 to Binary 128 64 32 16 8 4 2 1 1 0 0 1 1 1 1 0 156 - 128 = 28 28 - 16 = 12 12 - 8 = 4 4 - 4 = 0 Result: 10011100โ‚‚ = 156โ‚โ‚€

2.2 Binary to Denary Conversion

Converting binary to denary is straightforward - simply add up the positional values where there is a 1.

๐Ÿ“ Method: Add Positional Values
  1. Write the binary number
  2. Write the powers of 2 above each bit position
  3. Multiply each bit by its positional value
  4. Add all the results together
Example: Convert 11010010 to Denary 128 64 32 16 8 4 2 1 1 1 0 1 0 0 1 0 128 + 64 + 16 + 2 = 210โ‚โ‚€
๐Ÿ’ก Exam Tip

Quick Check: A binary number is odd if its rightmost digit (LSB) is 1, and even if it's 0!

Example: 11010010 ends in 0 โ†’ even (210 is even) โœ“

3. Denary โ†” Hexadecimal Conversions

3.1 Denary to Hexadecimal Conversion

There are two methods to convert denary to hexadecimal. Both are useful - choose based on the exam question!

๐Ÿ“ Method 1: Repeated Division by 16
  1. Divide the denary number by 16
  2. Record the remainder (convert 10-15 to A-F)
  3. Use the quotient as the new number
  4. Repeat until the quotient is 0
  5. Read remainders from BOTTOM to TOP
Example: Convert 425 to Hexadecimal 425 รท 16 = 26 remainder 9 โ†‘ 26 รท 16 = 1 remainder 10 = A โ†‘ 1 รท 16 = 0 remainder 1 โ†‘ Read bottom โ†’ top: 1A9โ‚โ‚†
๐Ÿ“ Method 2: Via Binary (Two-Step Method)
  1. Convert denary to binary first
  2. Split the binary into nibbles (groups of 4 bits) from the right
  3. Convert each nibble to its hex equivalent
  4. Join the hex digits together
Example: Convert 425 to Hex (via Binary) Step 1: 425โ‚โ‚€ = 110101001โ‚‚ Step 2: Split into nibbles (pad with zeros on left): 0001 1010 1001 = 1 = 10 = A = 9 = 1A9โ‚โ‚†

3.2 Hexadecimal to Denary Conversion

Multiply each hex digit by its positional value (powers of 16) and add them together.

๐Ÿ“ Method: Positional Value Method
  1. Write down each hex digit
  2. Convert letters A-F to their decimal values (A=10, B=11, ... F=15)
  3. Multiply each digit by 16 raised to its position power
  4. Add all results together
Example: Convert 2F3 to Denary 16ยฒ = 256 16ยน = 16 16โฐ = 1 2 F 3 (2 ร— 256) + (15 ร— 16) + (3 ร— 1) = 512 + 240 + 3 = 755โ‚โ‚€
Another Example: Convert BE to Denary
B = 11, E = 14
BEโ‚โ‚† = (11 ร— 16ยน) + (14 ร— 16โฐ) = (11 ร— 16) + (14 ร— 1) = 176 + 14 = 190โ‚โ‚€
๐Ÿง  Memory Trick

Hex Letter Values:

A = 10, B = 11, C = 12, D = 13, E = 14, F = 15

Think: A starts at 10, and counts up! F = Final = 15 (the last single hex digit)

4. Binary โ†” Hexadecimal Conversions

Binary and hexadecimal have a special relationship: each hex digit equals exactly 4 bits (one nibble)! This makes conversions between them very quick and easy.

4.1 Binary to Hexadecimal Conversion

๐Ÿ“ Method: Nibble Grouping
  1. Start from the right side of the binary number
  2. Group bits into sets of 4 (nibbles)
  3. If the leftmost group has fewer than 4 bits, pad with leading zeros
  4. Convert each nibble to its hex equivalent (0-F)
  5. Join all hex digits together
Binary 00000001001000110100010101100111
Hex 01234567
Binary 10001001101010111100110111101111
Hex 89ABCDEF
Example 1: Convert 10110111 to Hex 1011 8+2+1=11=B 0111 4+2+1=7 B7โ‚โ‚†
Example 2: Convert 11010 to Hex (needs padding!) Step 1: 11010 โ†’ pad to 00011010 0001 = 1 1010 = 10 = A 1Aโ‚โ‚†

4.2 Hexadecimal to Binary Conversion

๐Ÿ“ Method: Digit-by-Digit Conversion
  1. Take each hex digit separately
  2. Convert each hex digit to its 4-bit binary equivalent
  3. Join all the nibbles together
  4. Leading zeros from the leftmost nibble can be removed (optional)
Example 1: Convert 3F to Binary 3 0011 F 1111 Join together: 00111111โ‚‚
Example 2: Convert A5D to Binary A 1010 5 0101 D 1101 Join together: 101001011101โ‚‚
๐Ÿ’ก Exam Tip

Quick conversions between Hex and Binary are essential!

Memorize the 16 nibble patterns (0000 to 1111) and their hex equivalents. This makes conversions almost instant!

Tip: The decimal value 8 = binary 1000 = hex 8. Everything above 8 (9-F) has the 8-bit set!

5. Binary Prefixes

When measuring data storage, there are two systems of prefixes: decimal (denary) prefixes based on powers of 10, and binary prefixes based on powers of 2. Understanding the difference is crucial for accurate calculations.

Decimal Unit Value Binary Unit Value
Kilobyte (KB) 10ยณ = 1,000 Kibibyte (KiB) 2ยนโฐ = 1,024
Megabyte (MB) 10โถ = 1,000,000 Mebibyte (MiB) 2ยฒโฐ = 1,048,576
Gigabyte (GB) 10โน = 1,000,000,000 Gibibyte (GiB) 2ยณโฐ = 1,073,741,824
Terabyte (TB) 10ยนยฒ = 1,000,000,000,000 Tebibyte (TiB) 2โดโฐ = 1,099,511,627,776
Petabyte (PB) 10ยนโต = 1,000,000,000,000,000 Pebibyte (PiB) 2โตโฐ = 1,125,899,906,842,624
๐Ÿ’ก When to Use Which?
๐ŸŒŸ Why the Difference Matters

Have you ever bought a "500 GB" hard drive and found it shows less space in Windows? That's because Windows uses binary prefixes (GiB) but labels them as GB!

500 GB รท 1.024 รท 1.024 รท 1.024 โ‰ˆ 465 GiB (what Windows shows)

The manufacturer is correct (500 GB = 500 billion bytes), but Windows displays it in binary units!

๐Ÿง  Memory Trick

"ibi" for Binary

Kibi, Mebi, Gibi, Tebi - all have "ibi" which sounds like "binary"

Kilo, Mega, Giga, Tera - standard metric prefixes (base 10)

6. Binary Arithmetic & Overflow

6.1 Binary Addition Rules

Binary addition follows specific rules similar to decimal addition. When the sum exceeds what can be represented in a single column, a carry is generated.

๐Ÿ“– Binary Addition Rules
Binary Addition: 37 + 58 = 95 128 64 32 16 8 4 2 1 37: 0 0 1 0 0 1 0 1 58: 0 0 1 1 1 0 1 0 95: 0 1 0 1 1 1 1 1 64+32+8+1=95 32+16+8+2=58 64+16+8+4+2+1=95

6.2 Binary Subtraction

Binary subtraction can be performed directly or using the two's complement method. The two's complement method is preferred as it converts subtraction into addition.

๐Ÿ“– Binary Subtraction Rules (Direct Method)
โš ๏ธ Two's Complement Subtraction Method

To calculate A - B:

  1. Convert both numbers to binary
  2. Find the two's complement of B (the number being subtracted)
  3. Add A to the two's complement of B
  4. Discard any overflow bit (the 9th bit)
Example: Calculate 95 - 68 using two's complement
95 = 01011111โ‚‚
68 = 01000100โ‚‚ โ†’ Two's complement: 10111100โ‚‚
Add: 01011111 + 10111100 = 100011011
Discard overflow bit: 00011011โ‚‚ = 27โ‚โ‚€ โœ“ (95 - 68 = 27)

6.3 Overflow

Overflow occurs when the result of a calculation is too large to be stored in the allocated number of bits. For example, an 8-bit unsigned system can only store values from 0 to 255.

โŒ Common Mistake: 8-bit Overflow

Example: 255 + 1 in an 8-bit system

11111111 + 1 = 100000000

The 9th bit cannot be stored, so result becomes 00000000 = 0!

This is an error - the computer "wraps around" to the wrong answer.

7. Internal Coding of Integers

Computers need to represent both positive and negative integers. There are several methods to achieve this, each with advantages and limitations.

7.1 Unsigned Integers

Unsigned integers can only represent non-negative values. All bits are used for the magnitude.

๐Ÿ“– Unsigned Integer Range

7.2 Sign and Magnitude

In sign and magnitude, the leftmost bit (MSB) is the sign bit: 0 = positive, 1 = negative. Remaining bits store the magnitude.

Sign and Magnitude Examples (8-bit) +45: 0 0 1 0 1 1 0 1 Sign bit 0 = positive -45: 1 0 1 0 1 1 0 1 Sign bit 1 = negative
โŒ Disadvantages of Sign and Magnitude

7.3 Two's Complement (Standard Method)

Two's complement is the standard method for representing signed integers. It allows both positive and negative numbers to use the same addition/subtraction hardware.

๐Ÿ“ How to Find Two's Complement

Method 1:

  1. Find one's complement (invert all bits: 0โ†’1, 1โ†’0)
  2. Add 1 to the result

Method 2 (Shortcut):

From the right, keep all bits unchanged up to and including the first 1, then invert all remaining bits.

Find Two's Complement of 68 (01000100) Original: 0 1 0 0 0 1 0 0 Invert: 1 0 1 1 1 0 1 1 Add 1: 1 0 1 1 1 1 0 0 = -68 in two's complement!
๐Ÿ’ก Advantages of Two's Complement
๐Ÿ“– One's Complement

One's complement is found by inverting all bits. It's used as an intermediate step to find two's complement.

Example: One's complement of 10001001 = 01110110

8. BCD & Character Encoding

8.1 Binary Coded Decimal (BCD)

Binary Coded Decimal (BCD) represents each decimal digit (0-9) with its own 4-bit binary code. Each nibble represents one decimal digit separately.

๐Ÿ“– BCD Encoding Table

0 = 0000, 1 = 0001, 2 = 0010, 3 = 0011, 4 = 0100

5 = 0101, 6 = 0110, 7 = 0111, 8 = 1000, 9 = 1001

BCD Example: Convert 259 to BCD 2 0010 5 0101 9 1001 259โ‚โ‚€ = 0010 0101 1001
๐ŸŒŸ Practical Applications of BCD

8.2 Character Encoding

Computers represent text characters using numeric codes. Different character sets define which codes correspond to which characters.

๐Ÿ“– ASCII (American Standard Code for Information Interchange)
๐Ÿ“– Extended ASCII
โš ๏ธ Unicode - The Modern Standard
Character Set Bits Used Total Characters Notes
ASCII 7 bits 128 Basic English characters
Extended ASCII 8 bits 256 Regional variations
Unicode (UTF-8) 8-32 bits 1M+ Universal standard
๐Ÿง  Memory Trick

Remember the gap between 'A' and 'a':

'A' = 65, 'a' = 97 โ†’ Difference = 32

Upper to lower: Add 32 | Lower to upper: Subtract 32

9. Key Takeaways

๐Ÿ“Œ Summary Points

Topic 1: Number Systems

Topic 2: Number Conversions

Topic 3: Binary Prefixes

Topic 4: Binary Arithmetic

Topic 5: Integer Representation

Topic 6: BCD & Character Encoding

Representation 8-bit Range Key Feature
Unsigned Binary 0 to 255 Positive numbers only
Sign & Magnitude -127 to +127 Two zeros (+0, -0)
Two's Complement -128 to +127 Single zero, efficient

10. Exam-Style Questions (Part 1)

1. Convert the denary number 173 to binary using repeated division method. Show your working. [4 marks]

Answer:

  • 173 รท 2 = 86 remainder 1
  • 86 รท 2 = 43 remainder 0
  • 43 รท 2 = 21 remainder 1
  • 21 รท 2 = 10 remainder 1
  • 10 รท 2 = 5 remainder 0
  • 5 รท 2 = 2 remainder 1
  • 2 รท 2 = 1 remainder 0
  • 1 รท 2 = 0 remainder 1
  • Reading bottom to top: 10101101โ‚‚
2. Convert the hexadecimal number 3F to denary. Show your working. [3 marks]

Answer:

  • 3Fโ‚โ‚† = (3 ร— 16ยน) + (F ร— 16โฐ)
  • = (3 ร— 16) + (15 ร— 1)
  • = 48 + 15 = 63โ‚โ‚€
3. Convert the binary number 11011010 to hexadecimal. Show your working. [3 marks]

Answer:

  • Split into nibbles: 1101 1010
  • 1101 = 8+4+1 = 13 = D
  • 1010 = 8+2 = 10 = A
  • Result: DAโ‚โ‚†
4. Perform the binary addition: 01101101 + 00110110. Show your working and state if overflow occurs. [4 marks]

Answer:

  • 01101101 (109) + 00110110 (54)
  • = 10100011 (163)
  • No overflow occurs (result fits in 8 bits, 163 < 255)
  • Verification: 109 + 54 = 163 โœ“
5. Explain the difference between a kilobyte (KB) and a kibibyte (KiB). Give one example of when each would be appropriately used. [4 marks]

Answer:

  • Kilobyte (KB) uses decimal prefix: 1 KB = 1000 bytes (10ยณ)
  • Kibibyte (KiB) uses binary prefix: 1 KiB = 1024 bytes (2ยนโฐ)
  • KB is used for storage devices (hard drives, USB sticks)
  • KiB is used for RAM and precise memory calculations
6. Convert the denary number 425 to hexadecimal using BOTH methods: (a) repeated division by 16, and (b) via binary. [3 marks]

Answer:

Method (a) - Repeated Division:

  • 425 รท 16 = 26 remainder 9
  • 26 รท 16 = 1 remainder 10 (A)
  • 1 รท 16 = 0 remainder 1
  • Reading bottom to top: 1A9โ‚โ‚†

Method (b) - Via Binary:

  • 425โ‚โ‚€ = 110101001โ‚‚
  • Split: 0001 1010 1001
  • Convert: 1 A 9 โ†’ 1A9โ‚โ‚†

11. Exam-Style Questions (Part 2)

7. Represent the decimal number -45 as an 8-bit two's complement binary number. Show your working. [3 marks]

Answer:

  • Step 1: Convert 45 to binary: 00101101
  • Step 2: Invert all bits: 11010010
  • Step 3: Add 1: 11010011
  • This is -45 in two's complement
8. What is the range of values that can be represented using 8-bit two's complement? Explain why this differs from sign and magnitude. [3 marks]

Answer:

  • Two's complement range: -128 to +127
  • Sign and magnitude range: -127 to +127
  • Two's complement has only one representation of zero
  • This frees up one bit pattern (10000000) to represent -128
9. Explain what is meant by overflow in binary arithmetic. Give an example of when overflow could occur. [4 marks]

Answer:

  • Overflow occurs when a calculation result is too large for allocated bits
  • In 8-bit unsigned: adding 255 + 1 causes overflow
  • 11111111 + 1 = 100000000 (9 bits needed)
  • CPU drops overflow bit, result becomes 0 (incorrect!)
  • Overflow is a serious error that causes incorrect calculations
10. Explain two advantages of two's complement representation over sign and magnitude. [4 marks]

Answer:

  • Single zero: Two's complement has only one zero, avoiding +0/-0 confusion
  • Same hardware: Addition and subtraction use the same circuit for positive and negative numbers
  • Wider range: Can represent one extra negative value (-128 in 8-bit)
  • Self-complementary: Negating is simple (invert and add 1)
11. State what is meant by BCD and give one practical application where it is used. Explain why BCD is used instead of pure binary. [3 marks]

Answer:

  • BCD (Binary Coded Decimal) represents each decimal digit with 4 bits
  • Used in: digital displays (calculators, clocks), financial systems
  • Advantages: Easy decimal conversion, no rounding errors, simple display circuitry
  • Each digit converts directly for display without complex algorithms
12. Describe the difference between ASCII and Unicode. Why has Unicode become the preferred standard? [3 marks]

Answer:

  • ASCII uses 7 bits for 128 characters (basic English only)
  • Unicode can represent over 1 million characters (all world languages)
  • Unicode is preferred because it's universal - any language can be represented
  • UTF-8 encoding is backwards compatible with ASCII

๐Ÿ’ก Exam Success Tips

๐Ÿ† Top Tips for Acing Your Data Representation Exam
๐Ÿ’ก Last-Minute Checklist
๐Ÿง  Quick Memory Aids