Introduction to Computer Science
Topic 6
Data Representation
Numbers & Text
📘 Comprehensive Study Notes
Binary Systems • Number Conversion • ASCII & Unicode
Learning Outcomes
By the end of this topic, you will be able to:
• Describe how data is represented by the binary number system
• Demonstrate the addition of binary numbers
• Demonstrate the use of two's complement to represent negative binary numbers
• Describe how keyboard characters are stored using binary, including character sets
ASCII and Unicode
Part 1: Binary Number Systems
What is Binary?
A computer is built from transistors — tiny electronic switches that have exactly two states:
• ON = 1
• OFF = 0
Because there are only two possible states, computers use the binary number system (base 2).
Every piece of data — numbers, text, images, music — is ultimately stored as a sequence of 1s
and 0s.
💡 Key Vocabulary
Bit (Binary digit): A single 1 or 0 — the smallest unit of data. Byte: A group of 8 bits. One
byte can represent values from 0 to 255. Nibble: 4 bits (half a byte).
Why Binary?
Binary is used because:
• Electronic circuits naturally exist in two states (on/off, high/low voltage)
• It is reliable and simple to implement in hardware
• All modern CPUs contain billions of transistors operating on binary logic
Place Values in Binary
Binary uses powers of 2 as place values (just as decimal uses powers of 10). An 8-bit number
has these place values:
Position Place Value Power of 2
Bit 8 (leftmost) 128 2⁷
Bit 7 64 2⁶
Bit 6 32 2⁵
Bit 5 16 2⁴
Bit 4 8 2³
Bit 3 4 2²
Bit 2 2 2¹
Bit 1 (rightmost) 1 2⁰
Common Decimal-to-Binary Reference
Decimal Binary Notes
1 0000 0001
2 0000 0010
4 0000 0100
8 0000 1000
10 0000 1010
16 0001 0000
32 0010 0000
64 0100 0000
128 1000 0000 Max value of 7 bits
255 1111 1111 Max value of 8 bits
256 1 0000 0000 Requires 9 bits
Number Systems Overview
System Details
Decimal (Base 10) Uses digits 0-9. The everyday number system. E.g. 237
Binary (Base 2) Uses digits 0 and 1 only. E.g. 11101101
Hexadecimal (Base 16) Uses 0-9 and A-F. Shorter than binary. E.g. 9F = 159
Same value, three representations: 10011111 (binary) = 159 (decimal) = 9F (hexadecimal)
Converting Binary to Decimal
Method: Write the binary number under the place value headings. Where there is a 1, note the
place value. Add all noted place values together.
Worked Example 1: Convert 1000 1101 to decimal
Place values: 128 64 32 16 8 4 2 1
Binary digits: 1 0 0 0 1 1 0 1
Calculation: (1×128) + (1×8) + (1×4) + (1×1)
= 128 + 8 + 4 + 1
= 141
Worked Example 2: Convert 1110 0000 to decimal
Place values: 128 64 32 16 8 4 2 1
Binary digits: 1 1 1 0 0 0 0 0
Calculation: (1×128) + (1×64) + (1×32)
= 128 + 64 + 32
= 224
Converting Decimal to Binary
Method 1: Place Value Table
Step-by-step: Start from the leftmost (largest) place value. If the place value fits into your
number, put a 1 and subtract. If it doesn't fit, put a 0 and move on.
Worked Example: Convert 56 to binary
Target number: 56
Place values: 128 64 32 16 8 4 2 1
128 > 56 → 0
64 > 56 → 0
32 ≤ 56 → 1 (56 - 32 = 24 remaining)
16 ≤ 24 → 1 (24 - 16 = 8 remaining)
8 ≤ 8 → 1 (8 - 8 = 0 remaining)
4 > 0 → 0
2 > 0 → 0
1 > 0 → 0
Result: 0011 1000
Method 2: Repeated Division by 2
Divide the number by 2 repeatedly. Record the remainder each time. Read remainders from
bottom to top for the binary result.
Convert 12 to binary:
12 ÷ 2 = 6 remainder 0
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Read remainders bottom to top: 1100
Answer: 12 = 1100
Addition of Binary Numbers
There are four fundamental rules for binary addition:
Rule Binary Explanation
0+0 =0 No carry
0+1 =1 No carry
1+1 = 0, carry 1 Like decimal 10, we write 0 and carry 1
1+1+1 = 1, carry 1 Three 1s — write 1 and carry 1
Worked Example: Add 0110 + 0011
0 1 1 0
+ 0 0 1 1
---------
1 0 0 1
Step-by-step (right to left):
Col 1: 0+1 = 1 → write 1
Col 2: 1+1 = 0 carry 1 → write 0, carry 1
Col 3: 1+0+1(carry) = 0 carry 1 → write 0, carry 1
Col 4: 0+0+1(carry) = 1 → write 1
Result: 1001 = 9 (6 + 3 = 9 ✓)
⚠️Overflow Errors
An overflow error occurs when the result of a calculation requires more bits than the CPU
has allocated for storage. Example: Adding 1111 1111 + 1111 1111 on an 8-bit system
causes overflow — the result needs 9 bits but only 8 are available. Computers handle this
using overflow flags to signal that the result exceeded the storage capacity.
Binary Shift (Multiplication & Division)
Left Shift = Multiplication
Shifting all bits LEFT by n positions multiplies the number by 2ⁿ. Vacated positions on the right
are filled with 0s.
Original number: 0000 1100 = 12
Shift left by 2: 0011 0000 = 48
Effect: 12 × 4 = 48 (shifted by 2 positions → ×2² = ×4)
Right Shift = Division
Shifting all bits RIGHT by n positions divides the number by 2ⁿ. Vacated positions on the left are
filled with 0s. Note: accuracy may be lost if bits fall off the right end.
Original number: 0000 1100 = 12
Shift right by 2: 0000 0011 = 3
Effect: 12 ÷ 4 = 3 (shifted by 2 positions → ÷2² = ÷4)
📌 Quick Rule
Left shift n places → multiply by 2ⁿ Right shift n places → divide by 2ⁿ Examples: • Shift left
1 = ×2 • Shift left 3 = ×8 • Shift right 2 = ÷4
Two's Complement (Negative Numbers)
Computers use two's complement to store negative integers. This is the standard method used
in virtually all modern systems.
Steps to Find Two's Complement
• Step 1: Write the positive version of the number in binary (8 bits)
• Step 2: Invert all the bits (flip 0s to 1s and 1s to 0s)
• Step 3: Add 1 to the result
Worked Example: Express -28 in 8-bit two's complement
Step 1: Write 28 in binary → 0001 1100
Step 2: Invert all bits → 1110 0011
Step 3: Add 1 → 1110 0100
Answer: -28 = 1110 0100 in two's complement
💡 Key Insight
In two's complement, the leftmost bit (MSB) tells you the sign: • If MSB = 0 → the number is
positive • If MSB = 1 → the number is negative This allows a single 8-bit byte to represent
values from -128 to +127.
Part 2: Representation of Text
Why Do We Need Character Encoding?
Computers only understand numbers (binary). To store and transmit text, every character must
be assigned a unique numeric code. Character encoding systems define the mapping between
characters and their binary codes.
When you press a key on a keyboard, the keyboard sends a number to the computer. That
number is looked up in the character set table to identify which character it represents.
ASCII — American Standard Code for Information Interchange
Feature Details
Full Name American Standard Code for Information Interchange
Standard ASCII Uses 7 bits → represents 128 characters (0-127)
Extended ASCII Uses 8 bits → represents 256 characters (0-255)
Purpose Encoding English language characters for computers
Exam Note You do NOT need to memorise any ASCII codes for the
exam
The 128 Standard ASCII Characters Include:
• 32 control codes (e.g. newline, tab, backspace — mainly for printing)
• 32 punctuation marks, symbols, and the space character
• 26 uppercase letters (A-Z)
• 26 lowercase letters (a-z)
• 10 numeric digits (0-9)
Key ASCII Values to Know
Character Decimal Code Binary
'A' (uppercase A) 65 0100 0001
'B' (uppercase B) 66 0100 0010
'Z' (uppercase Z) 90 0101 1010
'a' (lowercase a) 97 0110 0001
'b' (lowercase b) 98 0110 0010
'0' (digit zero) 48 0011 0000
Space 32 0010 0000
💡 Useful Pattern
Lowercase letters have ASCII codes exactly 32 more than their uppercase equivalents.
Example: 'A' = 65, 'a' = 97 → 97 - 65 = 32 This means converting between cases is just a
matter of adding or subtracting 32.
How ASCII Works in Practice
When you type 'A', the computer stores the binary code for 65: 0100 0001. A page of Word text
(~1000 characters) takes approximately 1000 bytes of storage — one byte per character.
Extended ASCII
Standard ASCII (7-bit) only supports 128 characters — fine for English, but inadequate for other
languages.
Feature Details
Bits used 8 bits
Characters supported 256 characters (0-255)
Additional characters Accented letters (e.g. é, ñ, ü), currency symbols, box-drawing
characters
Suitable for Western European languages (French, Spanish, German,
etc.)
Limitation 256 characters is still far too few for languages like Chinese,
Arabic, or Japanese
Unicode — The Universal Character Encoding
Unicode was created to solve the limitations of ASCII by providing a universal encoding
standard that works for every language and writing system in the world.
Feature Details
Bits used 16 or more bits (UTF-8, UTF-16, UTF-32 are common
encodings)
Characters supported 65,000+ (16-bit) to over 1 million (with extensions)
Unicode 15.1 (2023) 149,813 characters across 161 scripts
Includes All alphabets worldwide, emojis, mathematical symbols,
ancient scripts
Memory usage Takes more memory than ASCII (more bits per character)
Most widely used UTF-8 is the dominant encoding on the internet
Languages Supported by Unicode (ASCII Cannot)
• Chinese (Mandarin, Cantonese) — tens of thousands of characters
• Arabic — right-to-left script
• Hindi and other Indian languages (supported via ISCII/Unicode)
• Russian (Cyrillic script)
• Japanese, Korean, Thai, and hundreds more
• Emoji — e.g. U+1F609 = 😉 (winking face)
📊 ASCII vs Unicode Comparison
ASCII (7-bit): 128 characters — English only Extended ASCII: 256 characters —
Western European languages Unicode (16-bit): 65,536 characters — All world languages +
emoji Unicode (full): 1,114,112 codes — Future expansion
Exam Practice & Quick Reference
Exam Questions with Worked Answers
Q1. What is ASCII and why do we use it?
Model Answer
ASCII (American Standard Code for Information Interchange) is a character encoding
standard that assigns a unique 7-bit binary code to each of 128 characters including letters,
digits, punctuation, and control codes. We use it because computers only understand binary
numbers; ASCII provides the mapping that allows text characters to be stored, transmitted,
and displayed on digital systems.
Q2. Convert 56 to binary
Place values: 128 64 32 16 8 4 2 1
0 0 1 1 1 0 0 0
32 + 16 + 8 = 56
Answer: 0011 1000
Q3. Convert 0101 0110 to decimal
Place values: 128 64 32 16 8 4 2 1
Bits: 0 1 0 1 0 1 1 0
(1×64) + (1×16) + (1×4) + (1×2)
= 64 + 16 + 4 + 2
= 86
Q4. What is the effect of a left 2-place binary shift?
Model Answer
A left 2-place binary shift multiplies the number by 4 (2²). All bits move two positions to the
left, and the two vacated positions on the right are filled with zeros. Note: if any 1-bits are
shifted off the left end, an overflow error occurs and data is lost.
Q5. Express -5 in Two's Complement (8-bit)
Step 1: Write 5 in binary → 0000 0101
Step 2: Invert all bits → 1111 1010
Step 3: Add 1 → 1111 1011
Answer: -5 = 1111 1011 in two's complement
Key Terms Glossary
Term Definition
Bit Binary digit — a single 0 or 1; the smallest unit of data
Byte 8 bits; can represent values 0–255
Binary Base-2 number system using only 0 and 1
Decimal Base-10 number system using digits 0–9 (everyday numbers)
Hexadecimal Base-16 number system using 0–9 and A–F
ASCII 7-bit character encoding for 128 English characters
Extended ASCII 8-bit encoding for 256 characters including accented letters
Unicode Universal 16-bit+ encoding supporting 65,000+ characters
worldwide
Two's Complement Method to represent negative integers in binary (invert + add
1)
Binary Shift Moving all bits left (×2ⁿ) or right (÷2ⁿ)
Overflow Error when a result exceeds the available number of bits
Character Set A defined mapping between characters and their numeric
codes
Mantissa The fractional part of a floating-point number
Floating Point Method of representing very large or very small numbers in
binary
Transistor A tiny electronic switch in a CPU — the physical basis of
binary
Fun Facts
• Unicode Day is celebrated on October 17th — the date Unicode 1.0 was released in
1991
• The emoji 😉 has the Unicode code point U+1F609
• Unicode 15.1 (2023) includes 149,813 characters across 161 different scripts
• A single page of text in Word (~1,000 characters) takes about 1,000 bytes in ASCII
• The ASCII control code 7 (BEL) used to literally ring a bell on old terminals
End of Topic 6 Notes
Introduction to Computer Science | Data Representation: Numbers & Text