SlideShare a Scribd company logo
Understanding
Data
Representation
AS LEVEL COMPUTER SCIENCE
Sekolah Bukit Sion
2025 - 2026
Chapter 1
1011010101001
1
...
Chapter
Outline
Number
System
1.1
Quantitative
Data
Representation
1.2
Numerical
Encoding
1.3
Text
Encoding
Digital Image
Representation
1.6
1.4
Data
Compression
Methods
1.7
1.5
Digital Sound
Representation
1.1 Number System
DENARY NUMBERS
• Base-10 number system
• 10 unique symbols (0,1,2,3,4,5,6,7,8,9)
• The value that a digit represents is defined by the place values of the digits in the number
Highlighter
1
1
0
10
0
3 6 5
1.1 Number System
DENARY NUMBERS
• Base-10 number system
• 10 unique symbols (0,1,2,3,4,5,6,7,8,9)
• The value that a digit represents is defined by the place values of the digits in the number
Highlighter
1
0
3 6 5
1
0
1
0
2 1 0
1.1 Number System
• Base-2 number system
• 2 unique symbols (0,1)
• Why Binary? Electronic components can only reliably represent two states: on/off or
high/low voltage.
BINARY NUMBERS
On =1
Off = 0
1.1 Number System
BINARY NUMBERS
1
2
4
1 0 1
8
1
6
32
1 1 0
64
12
8
1 0
Like in Denary, the value that a digit represents is defined by the
place values of the digits in the number.
1.1 Number System
BINARY NUMBERS
2
1 0 1
1 1 0
1 0
Like in Denary, the value that a digit represents is defined by the
place values of the digits in the number.
2
2
1
2
4
2
3
2
6
2
5
2 2
7 0
1.1 Number System
BINARY NUMBERS
1
2
4
1 0 1
8
1
6
32
1 1 0
64
12
8
1 0
8 bits = 1 byte
1.1 Number System
BINARY NUMBERS
1
2
4
1 0 1
8
1
6
32
1 1 0
64
12
8
1 0
4 bits = 1 nibble 4 bits = 1 nibble
1.1 Number System
1.1 Number System
Hexadecimal
• Base 16 number system
• 16 unique symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
• The value that a digit represents is defined by the place values of the digits in the
number
1
1
6
256
F 3 A
1.1 Number System
Hexadecimal
• Base 16 number system
• 16 unique symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
• The value that a digit represents is defined by the place values of the digits in the
number
F 3 A
1
6
1
6
1
6
2 1 0
1.1 Number System
Why Hexadecimal
• Hexadecimal simplifies binary representation, aiding memory addressing and byte
visualization.
• One nibble can be written by one hexadecimal digit.
0 0 0 1 1
Binary Hexadecimal
1.1 Number System
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
Binary Hexadecimal
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
james gan
1.1 Number System
1.1 Number System
0 1 1 1 0 1 0 1
1 1 1 0 1 0 1 0
7 E 5 A
7 5
E A
1.1 Number System
Error Codes IP Address
MAC Address
HTML Colour
Codes
Usages of Hexadecimal
1.1 Number System
Converting from binary to
denary
Multiply the digit value by the place
value.
1
2
4
1 0 1
8
1
6
1 0
1.1 Number System
Converting from binary to
denary
Multiply the digit value by the place
value.
1
2
4
1 0 1
8
1
6
1 0
(1x1) + (0x2) + (1x4) + (0x8) + (1x16)
= 21
1.1 Number System
Multiply the digit value by the place
value.
1
2
4
0 1 1
8
1
6
0 1
32
64
1 1
Converting from binary to
denary
1.1 Number System
Multiply the digit value by the place
value.
1
2
4
0 1 1
8
1
6
0 1
1 + 2 + 8 + 32 + 64
= 107
32
64
1 1
Converting from binary to
denary
1.1 Number System
5
2 2 1
Keep dividing the denary number by 2. Obtain
the remainder. Construct the answer.
Converting from denary to
binary
remainder
remainder
remainder
Read the remainder
from bottom to top
Binary = 101
Denary = 5
1.1 Number System
5
2
2
2
1
1
0
Keep dividing the denary number by 2. Obtain
the remainder. Construct the answer.
Converting from denary to
binary
remainder
remainder
remainder
Read the remainder
from bottom to top
Binary = 101
Denary = 5
1.1 Number System
5
2
2
2
1
1
0
Keep dividing the denary number by 2. Obtain
the remainder. Construct the answer.
Converting from denary to
binary
remainder
remainder
2 0 remainder
1
Read the remainder
from bottom to top
Binary = 101
Denary = 5
1.1 Number System
Keep dividing the denary number by 2. Obtain
the remainder. Construct the answer.
Converting from denary to
binary
Denary =39
Read the remainder
from bottom to top
39
2 19 1
remainder
remainder
remainder
remainder
remainder
remainder
1.1 Number System
Keep dividing the denary number by 2. Obtain
the remainder. Construct the answer.
Converting from denary to
binary
Binary = 100111
Denary =39
Read the remainder
from bottom to top
39
2
2
19
9
1
1
remainder
remainder
2 4 remainder
1
2 2 remainder
0
2 1 remainder
0
2 0 remainder
1
1.1 Number System
Look up / Create a binary to hexadecimal table
Converting from binary to
hexadecimal
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
Binary
0 1 1 1 1 1 1 0
1.1 Number System
Look up / Create a binary to hexadecimal table
Converting from binary to
hexadecimal
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
Binary
0 1 1 1 1 1 1 0
Hexadecimal
7 E
1.1 Number System
Look up / Create a binary to hexadecimal table
Converting from binary to
hexadecimal
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
Binary
0 1 1 1 1 1 1 0
Hexadecimal
7 E
1 1
?
1.1 Number System
Look up / Create a binary to hexadecimal table
Converting from binary to
hexadecimal
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
Binary
0 1 1 1 1 1 1 0
Hexadecimal
7 E
1 1
3
0 0
1.1 Number System
Look up / Create a binary to hexadecimal table
Converting from
hexadecimal to binary
Hexadecimal
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
3
C
? ? ?
?
? ? ?
?
Binary
1.1 Number System
Look up / Create a binary to hexadecimal table
Converting from
hexadecimal to binary
Hexadecimal
0 0 0 0 0
Binary Hexadecimal
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
3
C
0 1 1
0
1 0 0
1
Binary
1.1 Number System
Converting from
hexadecimal to denary
Multiply the digit value by the place
value.
1
1
6
256
2 A E
4096
1
= 10 = 15
1.1 Number System
Converting from
hexadecimal to denary
Multiply the digit value by the place
value.
1
1
6
256
2 A E
4096
1
(15x1) + (10x16) + (2x256) + (1x4096)
=4783
= 10 = 15
1.1 Number System
Keep dividing the denary number by 16. Obtain
the remainder. Construct the answer.
Converting from denary to
hexadecimal
Denary =3179
3179
16 198 remainder 11
remainder
remainder
Read the remainder
from bottom to top
= B
1.1 Number System
Keep dividing the denary number by 16. Obtain
the remainder. Construct the answer.
Converting from denary to
hexadecimal
Denary =3179
16 6
3179
16 198 remainder 11
12 remainder
remainder
Read the remainder
from bottom to top
= B
1.1 Number System
Keep dividing the denary number by 16. Obtain
the remainder. Construct the answer.
Converting from denary to
hexadecimal
Hexadecimal = C6B
Denary =3179
16 6
3179
16 198 remainder 11
12 remainder
16 0 remainder 12
Read the remainder
from bottom to top
= C
= B
Subtopic 1
In mathematics, here are a few ways that we can use to
represent large numbers ...
1.2 Quantitative Data Representation
• 689000 grams
• 6.89 x 10 grams
• 689 kilograms
5
Subtopic 1
Decimal Prefix table
Decimal Prefix Name Symbol used Factor applied to the value
kilo k 10
mega M 10
giga G 10
tera T 10
3
6
9
12
1.2 Quantitative Data Representation
Subtopic 1
• Why binary prefix? Computer works only with binary.
• When a new digit is added to the binary, the value is multiplied by 2. Eg
⚬ 1 (binary) = 1
⚬ 10 (binary) = 2
⚬ 100 (binary) = 4
⚬ 10000000000 (binary) = 1024 = kibi
Binary Prefix Name Symbol used
Factor applied to the
value
Kibi Ki 2
Mebi Mi 2
Gibi Gi 2
binary prefix
10
20
30
40
1.2 Quantitative Data Representation
Subtopic 1
Storage Terminology Overview
1 1
1 0
4 bits = 1 nibble
1 0 1
1 1 0
1 0
8 bits = 1 byte
1024 x
1 0 1
1 1 0
1 0
8 bits = 1 byte
1 kibi
bytes
1 mebi
bytes
1024 x 1024 x
1 0 1
1 1 0
1 0
8 bits = 1 byte
1 kibi
bytes
...
1.2 Quantitative Data Representation
Subtopic 1
Storage Conversion Cheatsheet
Bit
Byte
Kibibytes (KiB)
Mebibytes (MiB)
Gibibytes (GiB)
Tebibytes (TiB)
x8
x1024
x1024
x1024
x1024
8
1024
1024
1024
1024
1.2 Quantitative Data Representation
Subtopic 1
Exercise
Convert 8756000 bytes to Mebibytes.
8756000 / 1024 = 8550 kibibytes
Bit
Byte
Kibibytes (KiB)
Mebibytes (MiB)
Gibibytes (GiB)
Tebibytes (TiB)
x8
x1024
x1024
x1024
x1024
8
1024
1024
1024
1024
1.2 Quantitative Data Representation
Subtopic 1
Exercise
Convert 8756000 bytes to Mebibytes.
8756000 / 1024 = 8550 kibibytes
8550/ 1024 = 8.34 Mebibytes
Bit
Byte
Kibibytes (KiB)
Mebibytes (MiB)
Gibibytes (GiB)
Tebibytes (TiB)
x8
x1024
x1024
x1024
x1024
8
1024
1024
1024
1024
1.2 Quantitative Data Representation
Subtopic 1
Exercise
Convert 1.34 Gibibytes to Kibibytes.
1.34 x 1024 = 1372 Mebibytes
Bit
Byte
Kibibytes (KiB)
Mebibytes (MiB)
Gibibytes (GiB)
Tebibytes (TiB)
x8
x1024
x1024
x1024
x1024
8
1024
1024
1024
1024
1.2 Quantitative Data Representation
Subtopic 1
Exercise
Convert 1.34 Gibibytes to Kibibytes.
1.34 x 1024 = 1372 Mebibytes
1372 x 1024 = 140, 4928 Kibibytes
Bit
Byte
Kibibytes (KiB)
Mebibytes (MiB)
Gibibytes (GiB)
Tebibytes (TiB)
x8
x1024
x1024
x1024
x1024
8
1024
1024
1024
1024
1.2 Quantitative Data Representation
1.3 Numerical Encoding
Positive Integer
Eg. 107
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
0 1 1
8
1
6
0 1
1 + 2 + 8 + 32 + 64
= 107
32
64
1 1
Negative Integer
-32 ?
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
? ? ?
8
1
6
? ?
32
64
? ?
1.3 Numerical Encoding
Negative Integer
-32 ?
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
? ? ?
8
1
6
? ?
32
-64
? ?
Solution:
Make the leftmost
bit the signed bit
0 = Positive
1 = Negative
1.3 Numerical Encoding
Negative Integer
-32 ?
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
0 0 0
8
1
6
0 0
32
-64
1 1
1.3 Numerical Encoding
Negative Integer
-7 ?
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
? ? ?
-8
?
1.3 Numerical Encoding
Negative Integer
-7 ?
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
0 0 1
-8
1
1.3 Numerical Encoding
Negative Integer
Convert the two's complement 1110011 into denary.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
0 1 1
-64
1
8
1
6
32
1 1 0
1.3 Numerical Encoding
Negative Integer
Convert the two's complement 1110011 into denary.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
0 1 1
-64
1
8
1
6
32
1 1 0
-64 + 32 + 16 + 2 + 1
= -13
1.3 Numerical Encoding
Negative Integer
Give the smallest and largest two’s complement binary number that can be represented using 8
bits.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
? ? ?
-128
?
8
1
6
32
? ? ?
64
?
1.3 Numerical Encoding
Negative Integer
Give the smallest and largest two’s complement binary number that can be represented using 8
bits.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
0 0 0
-128
1
8
1
6
32
0 0 0
Smallest:
64
0
1.3 Numerical Encoding
Negative Integer
Give the smallest and largest two’s complement binary number that can be represented using 8
bits.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
1 1 1
-128
0
8
1
6
32
1 1 1
Largest:
64
1
james gan
1.3 Numerical Encoding
Negative Integer
Facts: You can get the same denary value even if you have two different two's complement value.
Eg.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1
2
4
1 0 0
-16
1
8
1
1110
0
1
2
4
1 0 0
-8
1
1100
-8 + 4
= -4
-16 + 8 + 4
= -4
1.3 Numerical Encoding
729
Binary Arithmetic - Adding
Before considering how to add 2 binary numbers, let's revise how we add 2
denary numbers ...
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
593
+
1322
1
1
1
Carry
All the possible digits in denary:
0,1,2,3,4,5,6,7,8,9
1.3 Numerical Encoding
101
Binary Arithmetic - Adding
Notes:
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
111
+
0
1
Carry
All the possible digits in binary:
0,1
0+0 = 0
0+1 = 1
1+0 = 0
1+1 = 10
1+1+1 = 11
1.3 Numerical Encoding
101
Binary Arithmetic - Adding
Notes:
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
111
+
00
1
1
Carry
All the possible digits in binary:
0,1
0+0 = 0
0+1 = 1
1+0 = 0
1+1 = 10
1+1+1 = 11
1.3 Numerical Encoding
101
Binary Arithmetic - Adding
Notes:
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
111
+
1100
1
1
1
Carry
All the possible digits in binary:
0,1
0+0 = 0
0+1 = 1
1+0 = 0
1+1 = 10
1+1+1 = 11
1.3 Numerical Encoding
729
Binary Arithmetic - Subtracting
Before considering how to subtract binary numbers, let's revise how carry out
subtraction for denary numbers
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1593
-
864
1
1
Borrow
All the possible digits in denary:
0,1,2,3,4,5,6,7,8,9
1.3 Numerical Encoding
011
Notes:
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
110
-
11
1
1
Borrow
All the possible digits in binary:
0,1
0-0 = 0
0-1 = 1 (after
borrow)
1-0 =1
1-1 =0
Binary Arithmetic - Subtracting
1.3 Numerical Encoding
10111011
Overflow problem in binary addition
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
11110011
+
110101110
1
1
1
Carry
1
1
1
An occurrence where the outcome of a computation
exceeds bit-defined storage.
1.3 Numerical Encoding
10111011
Overflow problem in binary addition
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
11110011
+
110101110
1
1
1
Carry
1
1
1
0 1 1
1 1 0
1
1
0 1 1
1 1 1
0
1
1 1 0
1 0 1
0
1
CPU View
Register
Register
Register
1
Lost bit
An occurrence where the outcome of a computation
exceeds bit-defined storage.
1.3 Numerical Encoding
00111011
Overflow problem in binary addition
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
01110011
+
10101110
1
1
1
1
1
Overflow problem can result in problems when 2 two's
complement are added.
= 115
= 115
= - 82
This is why we need
processor to detect
overflow and output an
error message (to be
discussed in C6).
1.3 Numerical Encoding
Binary Coded Decimal (BCD)
Binary Coded Decimal (BCD) is a coding
scheme representing each decimal digit
with its binary equivalent (4 bits) to enable
accurate arithmetic operations.
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
0
1
2
3
4
5
6
7
8
9
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
Denary Binary
1.3 Numerical Encoding
Binary Coded Decimal (BCD)
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
3 8 9
1 0 0 1
1
2
4
8
0 0 1 1
1
2
4
8
1 0 0 0
1
2
4
8
1.3 Numerical Encoding
Types of BCD - One BCD Per Byte
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
3 5 7 3
0 0 1 1
0 0
0 0 0 1 0 1
0 0
0 0 0 1 1 1
0 0
0 0 0 0 1 1
0 0
0 0
james gan
1.3 Numerical Encoding
Types of BCD - Packed BCD / Two BCD
Per Byte
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
3 5 7 3
0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1
1.3 Numerical Encoding
Packed BCD / Two BCD Per Byte
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
3 5 7 3
0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1
Types of BCD - One BCD Per Byte
3 5 7 3
0 0 1 1
0 0
0 0 0 1 0 1
0 0
0 0 0 1 1 1
0 0
0 0 0 0 1 1
0 0
0 0
1.3 Numerical Encoding
Binary Coded Decimal
Application examples: Calculator, where denary digits are to be displayed. Also
include floating point numbers (More detail in chapter 16).
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
1.3 Numerical Encoding
BCD Addition
Say we want to add up the following numbers (assume that 2-bytes packed BCD is used):
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
0.87
0.28
1 0 0 0 0 1 1 1
1 0 0 0
0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
+
1 1 1 1
1 0 1 0
0 0 0 0 0 0 0 0
Invalid Invalid
1.3 Numerical Encoding
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
0.87
0.28
1 0 0 0 0 1 1 1
1 0 0 0
0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
+
1 1 1 1
1 0 1 0
0 0 0 0 0 0 0 0
Step 1: Add "0110"
to the least
significant nibble
+ 0 1 1 0
0 1 0 1
1
1.3 Numerical Encoding
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
0.87
0.28
1 0 0 0 0 1 1 1
1 0 0 0
0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
+
1 1 1 1
1 0 1 0
0 0 0 0 0 0 0 0
Step 2: Add
correction plus
carry to the next
nibble.
+ 0 1 1 0
0 1 0 1
1
0 0 0 1
1
1.3 Numerical Encoding
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
0.87
0.28
1 0 0 0 0 1 1 1
1 0 0 0
0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
+
1 1 1 1
1 0 1 0
0 0 0 0 0 0 0 0
Step 3: Add carry
to the next nibble.
+
0 1 0 1
0 0 0 1
1
0 0 0 1
1.3 Numerical Encoding
Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD)
0.87
0.28
1 0 0 0 0 1 1 1
1 0 0 0
0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
+
1 1 1 1
1 0 1 0
0 0 0 0 0 0 0 0
Correct Answer: 1 . 1 5
0 1 0 1
0 0 0 1 0 0 0 1
0 0 0 0
1.3 Numerical Encoding
1.4 Text Encoding
Storing text
For computer storage of text, a coding system is required,
assigning distinct binary codes to individual text
components.
Highlighter
ASCII Unicode
ASCII (American Standard Code
for Information Interchange) Highlighter
Bag
1.4 Text Encoding
ASCII (American Standard Code
for Information Interchange) Highlighter
Bag
0 0 0 1
0 1 0 0
0 0 0 1
0 1 1 0
0 1 1 1
0 1 1 0
B
a
g
1.4 Text Encoding
Facts on ASCII
Highlighter
• Limited number of the codes represent non-printing or control characters
• The majority of codes represent English text elements like uppercase and
lowercase letters, punctuation, digits, and arithmetic symbols.
1.4 Text Encoding
Facts on ASCII
Highlighter
• Limited number of the codes represent non-printing or control characters
• The majority of codes represent English text elements like uppercase and
lowercase letters, punctuation, digits, and arithmetic symbols.
• Codes for numbers and letters follow a sequential pattern.
• Uppercase and lowercase letter codes only vary in the value of bit 6.
• Extended ASCII uses all eight bits in a byte, allowing new characters to be
added to the list.
1.4 Text Encoding
Unicode
• Unicode aims to represent any possible text in code form. Eg. UTF-8.
⚬ The inclusion of 8 in the name indicates that this version of the standard
includes codes defined by one byte in addition to codes using two, three,
and four bytes.
• Each character code in Unicode is referred to as a code point. (Eg. U+0000).
• Structures of Unicode:
⚬ 1 byte code
⚬ 2 byte code
⚬ 3 byte code
⚬ 4 byte code
1.4 Text Encoding
1 byte code
0???????
Unicode Structure
2 byte code
110????? 10??????
3 byte code
1110???? 10?????? 10??????
4 byte code
11110??? 10?????? 10?????? 10??????
• The number of codes available is
determined by the number of bits that
are not pre-defined by the format.
7 x (?)
11 x (?)
14 x (?)
21 x (?)
= 2 combinations
= 2 combinations
= 2 combinations
= 2 combinations
7
11
14
21
1.4 Text Encoding
Unicode Structure
• An example to show why this is a clever
structure!
Assume that this is the binary code for a series of text:
1110 0101 10 010101 10 111001 110 01000 10 110101
We got a problem.
How does the computer know which unicode structure is this?
How does the computer decode the binary codes?
1.4 Text Encoding
Unicode Structure
• An example to show why this is a clever
structure!
Assume that this is the binary code for a series of text:
1110 0101 10 010101 10 111001 110 01000 10 110101
Answer, it reads the first few bits to identify whether it is a 1/2/3/4 byte
unicode.
1.4 Text Encoding
Unicode Structure
• An example to show why this is a clever
structure!
Assume that this is the binary code for a series of text:
1110 0101 10 010101 10 111001 110 01000 10 110101
Answer, it reads the first few bits to identify whether it is a 1/2/3/4 byte
unicode.
First, it reads the first 4 bits (1110) and identify that this is the starting bits of a 3-byte
unicode. It now knows that the following 3 bytes are in continuation and find the
corresponding character.
1)
1.4 Text Encoding
Unicode Structure
• An example to show why this is a clever
structure!
Assume that this is the binary code for a series of text:
1110 0101 10 010101 10 111001 110 01000 10 110101
Answer, it reads the first few bits to identify whether it is a 1/2/3/4 byte
unicode.
First, it reads the first 4 bits (1110) and identify that this is the starting bits of a 3-byte
unicode. It now knows that the following 3 bytes are in continuation and find the
corresponding character.
1)
Upon finished decoding the 3-byte unicode. It detects that the following binary bits (110)
are the starting code for a 2 byte unicode. It then knows that the following 2 bytes are in
continuation.
2)
1.4 Text Encoding
1 byte code
0???????
Unicode Structure
2 byte code
110????? 10??????
3 byte code
1110???? 10?????? 10??????
4 byte code
11110??? 10?????? 10?????? 10??????
• The initial bits in the byte sequence for a
UTF-8 encoded character serve as
markers that indicate how many bytes
are used to represent that character.
These initial bits help the computer
distinguish between characters encoded
with 1, 2, 3, or 4 bytes.
1.4 Text Encoding
Subtopic 1
1.5 Digital Sound Representation
Recording sound
For storage or electronic transmission of sound, the initial analog sound
signal must undergo conversion into binary code.
Sound
Encoder
Band-limiting filter
• Eliminate inaudible high-
frequency elements to
avoid coding issues they
might pose.
ADC Converter
• Converts analogue data
to digital data
Subtopic 1
Sampling operation of the ADC
1 2 3 4 5 6 7 8 9 10
time
1
2
3
4
5
6
7
8
amplitude
sampling time
approximated
amplitude
1.5 Digital Sound Representation
Subtopic 1
Properties of digital sound
1 2 3 4 5 6 7 8 9 10
time
1
2
3
4
5
6
7
8
amplitude
Sampling Resolution: The number of bits used to store each sample
Sampling resolution = 3
1 2 3 4 5 6 7 8 9 10
time
amplitude
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Sampling resolution = 4
In practical terms, 16 bits offer sufficient accuracy for digitized sound.
1.5 Digital Sound Representation
Subtopic 1
Properties of digital sound
1 2 3 4 5 6 7 8 9 10
time
1
2
3
4
5
6
7
8
amplitude
Sampling Rate = Number of samples taken per second.
Both higher sampling rates and resolutions lead to larger file sizes.
1.5 Digital Sound Representation
Subtopic 1
Calculating the size of sound file
Formula: Sampling Rate x
Sampling Resolution x Time (s)
(Optional)
X2 for stereo sound
The following information refers to a music track being recorded:
• Sampling Rate: 44100 times per second
• Sampling Resolution:8 bits
• Length: 1 minute
• Type: Stereo
Calculate its file size in MiB.
1.5 Digital Sound Representation
Subtopic 1
Calculating the size of sound file
Formula: Sampling Rate x
Sampling Resolution x Time (s)
(Optional)
X2 for stereo sound
The following information refers to a music track being recorded:
• Sampling Rate: 44100 times per second
• Sampling Resolution:8 bits
• Length: 1 minute
• Type: Stereo
Calculate its file size in MiB.
44100 x 8 x 60 x 2
= 42336000 bits / 8
= 5292000 bytes / 1024
= 5167 KiB /1024
= 5.04 MiB
1.5 Digital Sound Representation
1.6 Digital Image Representation
Vector Graphics
Vector graphics are images defined by mathematical equations, allowing for scalability
without loss of quality.
Vector
graphics
contains a
drawing list
The list contains contains a command
for each object in the image.
Vector Graphics
Vector graphics are images defined by mathematical equations, allowing for scalability
without loss of quality.
Vector
graphics
contains a
drawing list
The list contains contains a command
for each object in the image.
Each command has a list of
attributes, with each attribute
defines the property of the object.
Eg. Basic geometric data, colours,
thickness, etc
Circle(30,80,10, purple, filled)
Draw Circle from (30,80),
radius 10 filled in purple
=
1.6 Digital Image Representation
Vector Graphics
In vector graphics, the significant characteristic is that object dimensions aren't directly
specified; instead, they're relative to an imaginary drawing surface. This means that the
quality of the file will not be affected is it scales.
Normal Image Vector Graphic
1.6 Digital Image Representation
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Bitmaps
Since many images lack defined shapes, using vector graphics is unsuitable. Typically, images
are stored as bitmaps.
1.6 Digital Image Representation
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Binary
Code
Bitmaps
Since many images lack defined shapes, using vector graphics is unsuitable. Typically, images
are stored as bitmaps.
Pixel
The smallest
identifiable
component of a
bitmap image
Each binary code
represent a
colour
1.6 Digital Image Representation
Bitmaps
Since many images lack defined shapes, using vector graphics is unsuitable. Typically, images
are stored as bitmaps.
1.6 Digital Image Representation
Colours in a bitmap
Colour depth: The number of bits used to represent one pixel. The greater the colour depth,
the greater the number of colours that can be represented.
Colour depth: 1
Possible value:
0,1
0: Black
1: White
1.6 Digital Image Representation
Colours in a bitmap
Colour depth: The number of bits used to represent one pixel. The greater the colour depth,
the greater the number of colours that can be represented.
Colour depth: 1
Possible value:
0,1
0: Black
1: White
Colour depth:2
Possible value:
00 , 01, 10, 11
00: Blue, 01: Green
10: Yellow, 11: Red
1.6 Digital Image Representation
Colours in a bitmap
Colour depth: The number of bits used to represent one pixel. The greater the colour depth,
the greater the number of colours that can be represented.
Colour depth: 1
Possible value:
0,1
0: Black
1: White
Colour depth:2
Possible value:
00 , 01, 10, 11
00: Blue, 01: Green
10: Yellow, 11: Red
Colour depth:3
Possible value:
000 , 001, 010, 011, 100, 101, 110, 111
1.6 Digital Image Representation
Colours in a bitmap
Bit depth, an alternate term for color depth, refers to the count of bits employed for storing
red, green, and blue primary colors in the RGB color model.
The standard is to used 8 bits per primary colour, leading
to 256 x 256 x 256 possible number of colours per pixel.
10011001(R), 11010100(G), 10111001(B)
1.6 Digital Image Representation
Resolution in bitmap
Image resolution: The number of pixels in the bitmap file defined as the product of the width
and the height values. The higher the image resolution, the better the quality.
3px
3px
100x100 600x600
1.6 Digital Image Representation
Properties of images
• Image Resolution
• Colour depth
• Bit depth (RGB)
1.6 Digital Image Representation
10101101 10111101 10111101
10111101 00101101 11101101
10101100 00101101 11111101
Calculate image size
The image on the right has a
colour depth of 8. What is its size
in bytes?
Formula: Image Resolution x Colour Depth
1.6 Digital Image Representation
10101101 10111101 10111101
10111101 00101101 11101101
10101100 00101101 11111101
Calculate image size
The image on the right has a
colour depth of 8. What is its size
in bytes?
Formula: Image Resolution x Colour Depth
3 x 3 x 8 = 72 bits / 8
= 9 bytes
1.6 Digital Image Representation
Calculate image size
The image on the right has an image resolution
of 600x600 and a bit depth of 8 (8 bits for each
red, green, and blue. What is its size in MiB?
Formula: Image Resolution x Colour Depth
600 x 600 x 8 x 3
= 8640000 bits
1.6 Digital Image Representation
Calculate image size
The image on the right has an image resolution
of 600x600 and a bit depth of 8 (8 bits for each
red, green, and blue. What is its size in MiB?
Formula: Image Resolution x Colour Depth
600 x 600 x 8 x 3
= 8640000 bits / 8
= 1080000 bytes
= 1054 KiB
= 1.03 MiB
1.6 Digital Image Representation
Bitmap
• A bitmap file includes pixel data and a
header describing its construction, causing
the file size to exceed the graphic size.
1.6 Digital Image Representation
Vector graphic or bitmap
• Opt for vector graphics in architectural, engineering, or manufacturing design
diagrams.
• Convert vector graphics to bitmaps before printing via laser or inkjet.
• Digital cameras generate bitmaps by default.
• Choose bitmap files for embedding images in documents, publications, or web
pages.
1.6 Digital Image Representation
1.7 Data Compression Methods
Why is compression needed?
Bigger files demand greater storage and significantly slower transmission or download
rates.
Lossless
compression
Lossy compression
• File size shrinks without
losing data
• The process is reversible
to restore the original
file.
• File size decreases with
partial information loss
• Complete restoration of
the original file isn't
possible.
Lossless Compression
An effective compression tool identifies compressible patterns in files and is often
tailored for specific file types. We will learn two compression methods here.
1.7 Data Compression Methods
A compression method that encodes repeated byte values by
specifying their count and value. Eg. It works well with a bitmap file.
Run-length
encoding
10101101 10101101 10101101 10101101
10111101 10111101 10111101 10111101
10101100 10101100 10101100 10101100
10101101 10101101 10101101 10101101
10111101 10111101 10111101 10111101
10101100 10101100 10101100 10101100
Before RLE
1.7 Data Compression Methods
A compression method that encodes repeated byte values by
specifying their count and value. Eg. It works well with a bitmap file.
Run-length
encoding
10101101 10101101 10101101 10101101
10111101 10111101 10111101 10111101
10101100 10101100 10101100 10101100
10101101 10101101 10101101 10101101
10111101 10111101 10111101 10111101
10101100 10101100 10101100 10101100
Before RLE
10101101 00000100 (4)
10111101 00000100 (4)
10101100 00000100 (4)
After RLE
1.7 Data Compression Methods
It also works well with repeated text
Run-length
encoding
01100001 01100001 01100001 01100001
01100010 01100010 01100010 01100010
Before RLE (ASCII)
aaaa bbbb
1.7 Data Compression Methods
It also works well with repeated text
Run-length
encoding
01100001 01100001 01100001 01100001
01100010 01100010 01100010 01100010
Before RLE (ASCII)
01100001 00000100 (4)
01100010 00000100 (4)
After RLE
aaaa bbbb
1.7 Data Compression Methods
Principle: Analyzing text to identify common characters, which are
assigned shorter codes than one-byte coding. Eg.
Huffman
Encoding
Count the frequency of
each character in the
text:
• 'a': 5 times
• 'b': 2 times
• 'r': 2 times
• 'c': 1 time
• 'd': 1 time
Step 1
abracadabra
1.7 Data Compression Methods
a 0
b 10
r 110
c 1110
d 1111
Principle: Analyzing text to identify common characters, which are
assigned shorter codes than one-byte coding. Eg.
Huffman
Encoding
Count the frequency of
each character in the
text:
• 'a': 5 times
• 'b': 2 times
• 'r': 2 times
• 'c': 1 time
• 'd': 1 time
Step 1
abracadabra
Create Huffman coding
Step 2
1.7 Data Compression Methods
a 0
b 10
r 110
c 1110
d 1111
Principle: Analyzing text to identify common characters, which are
assigned shorter codes than one-byte coding. Eg.
Huffman
Encoding
Count the frequency of
each character in the
text:
• 'a': 5 times
• 'b': 2 times
• 'r': 2 times
• 'c': 1 time
• 'd': 1 time
Step 1
abracadabra
Create Huffman coding
Step 2 Step 3
Replace each character with its
assigned code to get the compressed
text:
01001101010011010101001001001000
1.7 Data Compression Methods
Lossy Compression
Lossy compression is applicable when less crucial sound or image details can be altered
without significant human perception.
Sound
• Technique 1: Capitalise on the
infrequent change of
successive sampled values.
• Technique 2: Convert individual
sample amplitudes to
amplitude difference.
Compression is achieved by
using a lower sample
resolution to store the
differences. 1 2 3 4 5 6 7 8 9 10
time
1
2
3
4
5
6
7
8
amplitude
1.7 Data Compression Methods
Lossy Compression
Lossy compression is applicable when less crucial sound or image details can be altered
without significant human perception.
Image
• Establish a coding scheme with
reduced colour depth.
Before compression
After compression
(Extreme)
1.7 Data Compression Methods

More Related Content

PPT
Cit 1101 lec 02
PPTX
Numbering Systems
PPTX
ARCsxfhcjkvmnfxcgbfgcxhvbxdfzxcgbfxgcvbnx3.pptx
PPT
PPT
PPT
SD & D Representing Positive Numbers
PPTX
IGCSE Computer Science Chapter 1 - Binary
PPTX
Hexadecimal Number System | conversions hexa to binary
Cit 1101 lec 02
Numbering Systems
ARCsxfhcjkvmnfxcgbfgcxhvbxdfzxcgbfxgcvbnx3.pptx
SD & D Representing Positive Numbers
IGCSE Computer Science Chapter 1 - Binary
Hexadecimal Number System | conversions hexa to binary

Similar to Cambridge AS Level Computer Science Ch 1 (20)

PDF
Number system
PPTX
Chapter 3.pptx
PPTX
2013 1
PPTX
21EC201– Digital Principles and system design.pptx
PPTX
Number System | Types of Number System | Binary Number System | Octal Number ...
PPTX
Number System.pptx
PPT
Number system
PPTX
DLD-Introduction.pptx
PDF
Number System.pdf
PPTX
04 chapter03 02_numbers_systems_student_version_fa16
PPTX
Number System
PPT
Chapter 1 Digital Systems and Binary Numbers.ppt
PPTX
Intro to IT Skills Lec 5 - English Department.pptx
PPT
Representation of Positive Numbers
PPTX
Types of number system , NUMBER SYSTEMNumber systems are the technique to rep...
PDF
Digital logic_ Number System.pdf advanced
PPT
lect1.ppt
PPT
2. Computer_Organization_unit_ 1_win.ppt
PPT
1. basic theories of information
PPTX
Chapter 2.1 introduction to number system
Number system
Chapter 3.pptx
2013 1
21EC201– Digital Principles and system design.pptx
Number System | Types of Number System | Binary Number System | Octal Number ...
Number System.pptx
Number system
DLD-Introduction.pptx
Number System.pdf
04 chapter03 02_numbers_systems_student_version_fa16
Number System
Chapter 1 Digital Systems and Binary Numbers.ppt
Intro to IT Skills Lec 5 - English Department.pptx
Representation of Positive Numbers
Types of number system , NUMBER SYSTEMNumber systems are the technique to rep...
Digital logic_ Number System.pdf advanced
lect1.ppt
2. Computer_Organization_unit_ 1_win.ppt
1. basic theories of information
Chapter 2.1 introduction to number system
Ad

Recently uploaded (20)

PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
20th Century Theater, Methods, History.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
Trump Administration's workforce development strategy
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
1_English_Language_Set_2.pdf probationary
PDF
Empowerment Technology for Senior High School Guide
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Computer Architecture Input Output Memory.pptx
20th Century Theater, Methods, History.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
FORM 1 BIOLOGY MIND MAPS and their schemes
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Weekly quiz Compilation Jan -July 25.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Trump Administration's workforce development strategy
History, Philosophy and sociology of education (1).pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
1_English_Language_Set_2.pdf probationary
Empowerment Technology for Senior High School Guide
What if we spent less time fighting change, and more time building what’s rig...
TNA_Presentation-1-Final(SAVE)) (1).pptx
Paper A Mock Exam 9_ Attempt review.pdf.
Ad

Cambridge AS Level Computer Science Ch 1

  • 1. Understanding Data Representation AS LEVEL COMPUTER SCIENCE Sekolah Bukit Sion 2025 - 2026 Chapter 1 1011010101001 1 ...
  • 3. 1.1 Number System DENARY NUMBERS • Base-10 number system • 10 unique symbols (0,1,2,3,4,5,6,7,8,9) • The value that a digit represents is defined by the place values of the digits in the number Highlighter 1 1 0 10 0 3 6 5
  • 4. 1.1 Number System DENARY NUMBERS • Base-10 number system • 10 unique symbols (0,1,2,3,4,5,6,7,8,9) • The value that a digit represents is defined by the place values of the digits in the number Highlighter 1 0 3 6 5 1 0 1 0 2 1 0
  • 5. 1.1 Number System • Base-2 number system • 2 unique symbols (0,1) • Why Binary? Electronic components can only reliably represent two states: on/off or high/low voltage. BINARY NUMBERS On =1 Off = 0
  • 6. 1.1 Number System BINARY NUMBERS 1 2 4 1 0 1 8 1 6 32 1 1 0 64 12 8 1 0 Like in Denary, the value that a digit represents is defined by the place values of the digits in the number.
  • 7. 1.1 Number System BINARY NUMBERS 2 1 0 1 1 1 0 1 0 Like in Denary, the value that a digit represents is defined by the place values of the digits in the number. 2 2 1 2 4 2 3 2 6 2 5 2 2 7 0 1.1 Number System
  • 8. BINARY NUMBERS 1 2 4 1 0 1 8 1 6 32 1 1 0 64 12 8 1 0 8 bits = 1 byte 1.1 Number System
  • 9. BINARY NUMBERS 1 2 4 1 0 1 8 1 6 32 1 1 0 64 12 8 1 0 4 bits = 1 nibble 4 bits = 1 nibble 1.1 Number System
  • 10. 1.1 Number System Hexadecimal • Base 16 number system • 16 unique symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) • The value that a digit represents is defined by the place values of the digits in the number 1 1 6 256 F 3 A 1.1 Number System
  • 11. Hexadecimal • Base 16 number system • 16 unique symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) • The value that a digit represents is defined by the place values of the digits in the number F 3 A 1 6 1 6 1 6 2 1 0 1.1 Number System
  • 12. Why Hexadecimal • Hexadecimal simplifies binary representation, aiding memory addressing and byte visualization. • One nibble can be written by one hexadecimal digit. 0 0 0 1 1 Binary Hexadecimal 1.1 Number System
  • 13. 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 Binary Hexadecimal 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F james gan 1.1 Number System
  • 14. 1.1 Number System 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 0 7 E 5 A 7 5 E A
  • 15. 1.1 Number System Error Codes IP Address MAC Address HTML Colour Codes Usages of Hexadecimal
  • 16. 1.1 Number System Converting from binary to denary Multiply the digit value by the place value. 1 2 4 1 0 1 8 1 6 1 0
  • 17. 1.1 Number System Converting from binary to denary Multiply the digit value by the place value. 1 2 4 1 0 1 8 1 6 1 0 (1x1) + (0x2) + (1x4) + (0x8) + (1x16) = 21
  • 18. 1.1 Number System Multiply the digit value by the place value. 1 2 4 0 1 1 8 1 6 0 1 32 64 1 1 Converting from binary to denary
  • 19. 1.1 Number System Multiply the digit value by the place value. 1 2 4 0 1 1 8 1 6 0 1 1 + 2 + 8 + 32 + 64 = 107 32 64 1 1 Converting from binary to denary
  • 20. 1.1 Number System 5 2 2 1 Keep dividing the denary number by 2. Obtain the remainder. Construct the answer. Converting from denary to binary remainder remainder remainder Read the remainder from bottom to top Binary = 101 Denary = 5
  • 21. 1.1 Number System 5 2 2 2 1 1 0 Keep dividing the denary number by 2. Obtain the remainder. Construct the answer. Converting from denary to binary remainder remainder remainder Read the remainder from bottom to top Binary = 101 Denary = 5
  • 22. 1.1 Number System 5 2 2 2 1 1 0 Keep dividing the denary number by 2. Obtain the remainder. Construct the answer. Converting from denary to binary remainder remainder 2 0 remainder 1 Read the remainder from bottom to top Binary = 101 Denary = 5
  • 23. 1.1 Number System Keep dividing the denary number by 2. Obtain the remainder. Construct the answer. Converting from denary to binary Denary =39 Read the remainder from bottom to top 39 2 19 1 remainder remainder remainder remainder remainder remainder
  • 24. 1.1 Number System Keep dividing the denary number by 2. Obtain the remainder. Construct the answer. Converting from denary to binary Binary = 100111 Denary =39 Read the remainder from bottom to top 39 2 2 19 9 1 1 remainder remainder 2 4 remainder 1 2 2 remainder 0 2 1 remainder 0 2 0 remainder 1
  • 25. 1.1 Number System Look up / Create a binary to hexadecimal table Converting from binary to hexadecimal 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F Binary 0 1 1 1 1 1 1 0
  • 26. 1.1 Number System Look up / Create a binary to hexadecimal table Converting from binary to hexadecimal 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F Binary 0 1 1 1 1 1 1 0 Hexadecimal 7 E
  • 27. 1.1 Number System Look up / Create a binary to hexadecimal table Converting from binary to hexadecimal 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F Binary 0 1 1 1 1 1 1 0 Hexadecimal 7 E 1 1 ?
  • 28. 1.1 Number System Look up / Create a binary to hexadecimal table Converting from binary to hexadecimal 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F Binary 0 1 1 1 1 1 1 0 Hexadecimal 7 E 1 1 3 0 0
  • 29. 1.1 Number System Look up / Create a binary to hexadecimal table Converting from hexadecimal to binary Hexadecimal 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F 3 C ? ? ? ? ? ? ? ? Binary
  • 30. 1.1 Number System Look up / Create a binary to hexadecimal table Converting from hexadecimal to binary Hexadecimal 0 0 0 0 0 Binary Hexadecimal 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F 3 C 0 1 1 0 1 0 0 1 Binary
  • 31. 1.1 Number System Converting from hexadecimal to denary Multiply the digit value by the place value. 1 1 6 256 2 A E 4096 1 = 10 = 15
  • 32. 1.1 Number System Converting from hexadecimal to denary Multiply the digit value by the place value. 1 1 6 256 2 A E 4096 1 (15x1) + (10x16) + (2x256) + (1x4096) =4783 = 10 = 15
  • 33. 1.1 Number System Keep dividing the denary number by 16. Obtain the remainder. Construct the answer. Converting from denary to hexadecimal Denary =3179 3179 16 198 remainder 11 remainder remainder Read the remainder from bottom to top = B
  • 34. 1.1 Number System Keep dividing the denary number by 16. Obtain the remainder. Construct the answer. Converting from denary to hexadecimal Denary =3179 16 6 3179 16 198 remainder 11 12 remainder remainder Read the remainder from bottom to top = B
  • 35. 1.1 Number System Keep dividing the denary number by 16. Obtain the remainder. Construct the answer. Converting from denary to hexadecimal Hexadecimal = C6B Denary =3179 16 6 3179 16 198 remainder 11 12 remainder 16 0 remainder 12 Read the remainder from bottom to top = C = B
  • 36. Subtopic 1 In mathematics, here are a few ways that we can use to represent large numbers ... 1.2 Quantitative Data Representation • 689000 grams • 6.89 x 10 grams • 689 kilograms 5
  • 37. Subtopic 1 Decimal Prefix table Decimal Prefix Name Symbol used Factor applied to the value kilo k 10 mega M 10 giga G 10 tera T 10 3 6 9 12 1.2 Quantitative Data Representation
  • 38. Subtopic 1 • Why binary prefix? Computer works only with binary. • When a new digit is added to the binary, the value is multiplied by 2. Eg ⚬ 1 (binary) = 1 ⚬ 10 (binary) = 2 ⚬ 100 (binary) = 4 ⚬ 10000000000 (binary) = 1024 = kibi Binary Prefix Name Symbol used Factor applied to the value Kibi Ki 2 Mebi Mi 2 Gibi Gi 2 binary prefix 10 20 30 40 1.2 Quantitative Data Representation
  • 39. Subtopic 1 Storage Terminology Overview 1 1 1 0 4 bits = 1 nibble 1 0 1 1 1 0 1 0 8 bits = 1 byte 1024 x 1 0 1 1 1 0 1 0 8 bits = 1 byte 1 kibi bytes 1 mebi bytes 1024 x 1024 x 1 0 1 1 1 0 1 0 8 bits = 1 byte 1 kibi bytes ... 1.2 Quantitative Data Representation
  • 40. Subtopic 1 Storage Conversion Cheatsheet Bit Byte Kibibytes (KiB) Mebibytes (MiB) Gibibytes (GiB) Tebibytes (TiB) x8 x1024 x1024 x1024 x1024 8 1024 1024 1024 1024 1.2 Quantitative Data Representation
  • 41. Subtopic 1 Exercise Convert 8756000 bytes to Mebibytes. 8756000 / 1024 = 8550 kibibytes Bit Byte Kibibytes (KiB) Mebibytes (MiB) Gibibytes (GiB) Tebibytes (TiB) x8 x1024 x1024 x1024 x1024 8 1024 1024 1024 1024 1.2 Quantitative Data Representation
  • 42. Subtopic 1 Exercise Convert 8756000 bytes to Mebibytes. 8756000 / 1024 = 8550 kibibytes 8550/ 1024 = 8.34 Mebibytes Bit Byte Kibibytes (KiB) Mebibytes (MiB) Gibibytes (GiB) Tebibytes (TiB) x8 x1024 x1024 x1024 x1024 8 1024 1024 1024 1024 1.2 Quantitative Data Representation
  • 43. Subtopic 1 Exercise Convert 1.34 Gibibytes to Kibibytes. 1.34 x 1024 = 1372 Mebibytes Bit Byte Kibibytes (KiB) Mebibytes (MiB) Gibibytes (GiB) Tebibytes (TiB) x8 x1024 x1024 x1024 x1024 8 1024 1024 1024 1024 1.2 Quantitative Data Representation
  • 44. Subtopic 1 Exercise Convert 1.34 Gibibytes to Kibibytes. 1.34 x 1024 = 1372 Mebibytes 1372 x 1024 = 140, 4928 Kibibytes Bit Byte Kibibytes (KiB) Mebibytes (MiB) Gibibytes (GiB) Tebibytes (TiB) x8 x1024 x1024 x1024 x1024 8 1024 1024 1024 1024 1.2 Quantitative Data Representation
  • 45. 1.3 Numerical Encoding Positive Integer Eg. 107 Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 0 1 1 8 1 6 0 1 1 + 2 + 8 + 32 + 64 = 107 32 64 1 1
  • 46. Negative Integer -32 ? Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 ? ? ? 8 1 6 ? ? 32 64 ? ? 1.3 Numerical Encoding
  • 47. Negative Integer -32 ? Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 ? ? ? 8 1 6 ? ? 32 -64 ? ? Solution: Make the leftmost bit the signed bit 0 = Positive 1 = Negative 1.3 Numerical Encoding
  • 48. Negative Integer -32 ? Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 0 0 0 8 1 6 0 0 32 -64 1 1 1.3 Numerical Encoding
  • 49. Negative Integer -7 ? Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 ? ? ? -8 ? 1.3 Numerical Encoding
  • 50. Negative Integer -7 ? Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 0 0 1 -8 1 1.3 Numerical Encoding
  • 51. Negative Integer Convert the two's complement 1110011 into denary. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 0 1 1 -64 1 8 1 6 32 1 1 0 1.3 Numerical Encoding
  • 52. Negative Integer Convert the two's complement 1110011 into denary. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 0 1 1 -64 1 8 1 6 32 1 1 0 -64 + 32 + 16 + 2 + 1 = -13 1.3 Numerical Encoding
  • 53. Negative Integer Give the smallest and largest two’s complement binary number that can be represented using 8 bits. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 ? ? ? -128 ? 8 1 6 32 ? ? ? 64 ? 1.3 Numerical Encoding
  • 54. Negative Integer Give the smallest and largest two’s complement binary number that can be represented using 8 bits. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 0 0 0 -128 1 8 1 6 32 0 0 0 Smallest: 64 0 1.3 Numerical Encoding
  • 55. Negative Integer Give the smallest and largest two’s complement binary number that can be represented using 8 bits. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 1 1 1 -128 0 8 1 6 32 1 1 1 Largest: 64 1 james gan 1.3 Numerical Encoding
  • 56. Negative Integer Facts: You can get the same denary value even if you have two different two's complement value. Eg. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1 2 4 1 0 0 -16 1 8 1 1110 0 1 2 4 1 0 0 -8 1 1100 -8 + 4 = -4 -16 + 8 + 4 = -4 1.3 Numerical Encoding
  • 57. 729 Binary Arithmetic - Adding Before considering how to add 2 binary numbers, let's revise how we add 2 denary numbers ... Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 593 + 1322 1 1 1 Carry All the possible digits in denary: 0,1,2,3,4,5,6,7,8,9 1.3 Numerical Encoding
  • 58. 101 Binary Arithmetic - Adding Notes: Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 111 + 0 1 Carry All the possible digits in binary: 0,1 0+0 = 0 0+1 = 1 1+0 = 0 1+1 = 10 1+1+1 = 11 1.3 Numerical Encoding
  • 59. 101 Binary Arithmetic - Adding Notes: Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 111 + 00 1 1 Carry All the possible digits in binary: 0,1 0+0 = 0 0+1 = 1 1+0 = 0 1+1 = 10 1+1+1 = 11 1.3 Numerical Encoding
  • 60. 101 Binary Arithmetic - Adding Notes: Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 111 + 1100 1 1 1 Carry All the possible digits in binary: 0,1 0+0 = 0 0+1 = 1 1+0 = 0 1+1 = 10 1+1+1 = 11 1.3 Numerical Encoding
  • 61. 729 Binary Arithmetic - Subtracting Before considering how to subtract binary numbers, let's revise how carry out subtraction for denary numbers Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1593 - 864 1 1 Borrow All the possible digits in denary: 0,1,2,3,4,5,6,7,8,9 1.3 Numerical Encoding
  • 62. 011 Notes: Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 110 - 11 1 1 Borrow All the possible digits in binary: 0,1 0-0 = 0 0-1 = 1 (after borrow) 1-0 =1 1-1 =0 Binary Arithmetic - Subtracting 1.3 Numerical Encoding
  • 63. 10111011 Overflow problem in binary addition Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 11110011 + 110101110 1 1 1 Carry 1 1 1 An occurrence where the outcome of a computation exceeds bit-defined storage. 1.3 Numerical Encoding
  • 64. 10111011 Overflow problem in binary addition Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 11110011 + 110101110 1 1 1 Carry 1 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 0 1 0 1 0 1 CPU View Register Register Register 1 Lost bit An occurrence where the outcome of a computation exceeds bit-defined storage. 1.3 Numerical Encoding
  • 65. 00111011 Overflow problem in binary addition Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 01110011 + 10101110 1 1 1 1 1 Overflow problem can result in problems when 2 two's complement are added. = 115 = 115 = - 82 This is why we need processor to detect overflow and output an error message (to be discussed in C6). 1.3 Numerical Encoding
  • 66. Binary Coded Decimal (BCD) Binary Coded Decimal (BCD) is a coding scheme representing each decimal digit with its binary equivalent (4 bits) to enable accurate arithmetic operations. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 Denary Binary 1.3 Numerical Encoding
  • 67. Binary Coded Decimal (BCD) Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 3 8 9 1 0 0 1 1 2 4 8 0 0 1 1 1 2 4 8 1 0 0 0 1 2 4 8 1.3 Numerical Encoding
  • 68. Types of BCD - One BCD Per Byte Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 3 5 7 3 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 james gan 1.3 Numerical Encoding
  • 69. Types of BCD - Packed BCD / Two BCD Per Byte Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 3 5 7 3 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1.3 Numerical Encoding
  • 70. Packed BCD / Two BCD Per Byte Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 3 5 7 3 0 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1 Types of BCD - One BCD Per Byte 3 5 7 3 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1.3 Numerical Encoding
  • 71. Binary Coded Decimal Application examples: Calculator, where denary digits are to be displayed. Also include floating point numbers (More detail in chapter 16). Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 1.3 Numerical Encoding
  • 72. BCD Addition Say we want to add up the following numbers (assume that 2-bytes packed BCD is used): Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 0.87 0.28 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 Invalid Invalid 1.3 Numerical Encoding
  • 73. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 0.87 0.28 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 Step 1: Add "0110" to the least significant nibble + 0 1 1 0 0 1 0 1 1 1.3 Numerical Encoding
  • 74. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 0.87 0.28 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 Step 2: Add correction plus carry to the next nibble. + 0 1 1 0 0 1 0 1 1 0 0 0 1 1 1.3 Numerical Encoding
  • 75. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 0.87 0.28 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 Step 3: Add carry to the next nibble. + 0 1 0 1 0 0 0 1 1 0 0 0 1 1.3 Numerical Encoding
  • 76. Positive Integer Negative Integer Binary Arithmetic Binary Coded Decimal (BCD) 0.87 0.28 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 Correct Answer: 1 . 1 5 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1.3 Numerical Encoding
  • 77. 1.4 Text Encoding Storing text For computer storage of text, a coding system is required, assigning distinct binary codes to individual text components. Highlighter ASCII Unicode
  • 78. ASCII (American Standard Code for Information Interchange) Highlighter Bag 1.4 Text Encoding
  • 79. ASCII (American Standard Code for Information Interchange) Highlighter Bag 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 B a g 1.4 Text Encoding
  • 80. Facts on ASCII Highlighter • Limited number of the codes represent non-printing or control characters • The majority of codes represent English text elements like uppercase and lowercase letters, punctuation, digits, and arithmetic symbols. 1.4 Text Encoding
  • 81. Facts on ASCII Highlighter • Limited number of the codes represent non-printing or control characters • The majority of codes represent English text elements like uppercase and lowercase letters, punctuation, digits, and arithmetic symbols. • Codes for numbers and letters follow a sequential pattern. • Uppercase and lowercase letter codes only vary in the value of bit 6. • Extended ASCII uses all eight bits in a byte, allowing new characters to be added to the list. 1.4 Text Encoding
  • 82. Unicode • Unicode aims to represent any possible text in code form. Eg. UTF-8. ⚬ The inclusion of 8 in the name indicates that this version of the standard includes codes defined by one byte in addition to codes using two, three, and four bytes. • Each character code in Unicode is referred to as a code point. (Eg. U+0000). • Structures of Unicode: ⚬ 1 byte code ⚬ 2 byte code ⚬ 3 byte code ⚬ 4 byte code 1.4 Text Encoding
  • 83. 1 byte code 0??????? Unicode Structure 2 byte code 110????? 10?????? 3 byte code 1110???? 10?????? 10?????? 4 byte code 11110??? 10?????? 10?????? 10?????? • The number of codes available is determined by the number of bits that are not pre-defined by the format. 7 x (?) 11 x (?) 14 x (?) 21 x (?) = 2 combinations = 2 combinations = 2 combinations = 2 combinations 7 11 14 21 1.4 Text Encoding
  • 84. Unicode Structure • An example to show why this is a clever structure! Assume that this is the binary code for a series of text: 1110 0101 10 010101 10 111001 110 01000 10 110101 We got a problem. How does the computer know which unicode structure is this? How does the computer decode the binary codes? 1.4 Text Encoding
  • 85. Unicode Structure • An example to show why this is a clever structure! Assume that this is the binary code for a series of text: 1110 0101 10 010101 10 111001 110 01000 10 110101 Answer, it reads the first few bits to identify whether it is a 1/2/3/4 byte unicode. 1.4 Text Encoding
  • 86. Unicode Structure • An example to show why this is a clever structure! Assume that this is the binary code for a series of text: 1110 0101 10 010101 10 111001 110 01000 10 110101 Answer, it reads the first few bits to identify whether it is a 1/2/3/4 byte unicode. First, it reads the first 4 bits (1110) and identify that this is the starting bits of a 3-byte unicode. It now knows that the following 3 bytes are in continuation and find the corresponding character. 1) 1.4 Text Encoding
  • 87. Unicode Structure • An example to show why this is a clever structure! Assume that this is the binary code for a series of text: 1110 0101 10 010101 10 111001 110 01000 10 110101 Answer, it reads the first few bits to identify whether it is a 1/2/3/4 byte unicode. First, it reads the first 4 bits (1110) and identify that this is the starting bits of a 3-byte unicode. It now knows that the following 3 bytes are in continuation and find the corresponding character. 1) Upon finished decoding the 3-byte unicode. It detects that the following binary bits (110) are the starting code for a 2 byte unicode. It then knows that the following 2 bytes are in continuation. 2) 1.4 Text Encoding
  • 88. 1 byte code 0??????? Unicode Structure 2 byte code 110????? 10?????? 3 byte code 1110???? 10?????? 10?????? 4 byte code 11110??? 10?????? 10?????? 10?????? • The initial bits in the byte sequence for a UTF-8 encoded character serve as markers that indicate how many bytes are used to represent that character. These initial bits help the computer distinguish between characters encoded with 1, 2, 3, or 4 bytes. 1.4 Text Encoding
  • 89. Subtopic 1 1.5 Digital Sound Representation Recording sound For storage or electronic transmission of sound, the initial analog sound signal must undergo conversion into binary code. Sound Encoder Band-limiting filter • Eliminate inaudible high- frequency elements to avoid coding issues they might pose. ADC Converter • Converts analogue data to digital data
  • 90. Subtopic 1 Sampling operation of the ADC 1 2 3 4 5 6 7 8 9 10 time 1 2 3 4 5 6 7 8 amplitude sampling time approximated amplitude 1.5 Digital Sound Representation
  • 91. Subtopic 1 Properties of digital sound 1 2 3 4 5 6 7 8 9 10 time 1 2 3 4 5 6 7 8 amplitude Sampling Resolution: The number of bits used to store each sample Sampling resolution = 3 1 2 3 4 5 6 7 8 9 10 time amplitude 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Sampling resolution = 4 In practical terms, 16 bits offer sufficient accuracy for digitized sound. 1.5 Digital Sound Representation
  • 92. Subtopic 1 Properties of digital sound 1 2 3 4 5 6 7 8 9 10 time 1 2 3 4 5 6 7 8 amplitude Sampling Rate = Number of samples taken per second. Both higher sampling rates and resolutions lead to larger file sizes. 1.5 Digital Sound Representation
  • 93. Subtopic 1 Calculating the size of sound file Formula: Sampling Rate x Sampling Resolution x Time (s) (Optional) X2 for stereo sound The following information refers to a music track being recorded: • Sampling Rate: 44100 times per second • Sampling Resolution:8 bits • Length: 1 minute • Type: Stereo Calculate its file size in MiB. 1.5 Digital Sound Representation
  • 94. Subtopic 1 Calculating the size of sound file Formula: Sampling Rate x Sampling Resolution x Time (s) (Optional) X2 for stereo sound The following information refers to a music track being recorded: • Sampling Rate: 44100 times per second • Sampling Resolution:8 bits • Length: 1 minute • Type: Stereo Calculate its file size in MiB. 44100 x 8 x 60 x 2 = 42336000 bits / 8 = 5292000 bytes / 1024 = 5167 KiB /1024 = 5.04 MiB 1.5 Digital Sound Representation
  • 95. 1.6 Digital Image Representation Vector Graphics Vector graphics are images defined by mathematical equations, allowing for scalability without loss of quality. Vector graphics contains a drawing list The list contains contains a command for each object in the image.
  • 96. Vector Graphics Vector graphics are images defined by mathematical equations, allowing for scalability without loss of quality. Vector graphics contains a drawing list The list contains contains a command for each object in the image. Each command has a list of attributes, with each attribute defines the property of the object. Eg. Basic geometric data, colours, thickness, etc Circle(30,80,10, purple, filled) Draw Circle from (30,80), radius 10 filled in purple = 1.6 Digital Image Representation
  • 97. Vector Graphics In vector graphics, the significant characteristic is that object dimensions aren't directly specified; instead, they're relative to an imaginary drawing surface. This means that the quality of the file will not be affected is it scales. Normal Image Vector Graphic 1.6 Digital Image Representation
  • 99. Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Binary Code Bitmaps Since many images lack defined shapes, using vector graphics is unsuitable. Typically, images are stored as bitmaps. Pixel The smallest identifiable component of a bitmap image Each binary code represent a colour 1.6 Digital Image Representation
  • 100. Bitmaps Since many images lack defined shapes, using vector graphics is unsuitable. Typically, images are stored as bitmaps. 1.6 Digital Image Representation
  • 101. Colours in a bitmap Colour depth: The number of bits used to represent one pixel. The greater the colour depth, the greater the number of colours that can be represented. Colour depth: 1 Possible value: 0,1 0: Black 1: White 1.6 Digital Image Representation
  • 102. Colours in a bitmap Colour depth: The number of bits used to represent one pixel. The greater the colour depth, the greater the number of colours that can be represented. Colour depth: 1 Possible value: 0,1 0: Black 1: White Colour depth:2 Possible value: 00 , 01, 10, 11 00: Blue, 01: Green 10: Yellow, 11: Red 1.6 Digital Image Representation
  • 103. Colours in a bitmap Colour depth: The number of bits used to represent one pixel. The greater the colour depth, the greater the number of colours that can be represented. Colour depth: 1 Possible value: 0,1 0: Black 1: White Colour depth:2 Possible value: 00 , 01, 10, 11 00: Blue, 01: Green 10: Yellow, 11: Red Colour depth:3 Possible value: 000 , 001, 010, 011, 100, 101, 110, 111 1.6 Digital Image Representation
  • 104. Colours in a bitmap Bit depth, an alternate term for color depth, refers to the count of bits employed for storing red, green, and blue primary colors in the RGB color model. The standard is to used 8 bits per primary colour, leading to 256 x 256 x 256 possible number of colours per pixel. 10011001(R), 11010100(G), 10111001(B) 1.6 Digital Image Representation
  • 105. Resolution in bitmap Image resolution: The number of pixels in the bitmap file defined as the product of the width and the height values. The higher the image resolution, the better the quality. 3px 3px 100x100 600x600 1.6 Digital Image Representation
  • 106. Properties of images • Image Resolution • Colour depth • Bit depth (RGB) 1.6 Digital Image Representation
  • 107. 10101101 10111101 10111101 10111101 00101101 11101101 10101100 00101101 11111101 Calculate image size The image on the right has a colour depth of 8. What is its size in bytes? Formula: Image Resolution x Colour Depth 1.6 Digital Image Representation
  • 108. 10101101 10111101 10111101 10111101 00101101 11101101 10101100 00101101 11111101 Calculate image size The image on the right has a colour depth of 8. What is its size in bytes? Formula: Image Resolution x Colour Depth 3 x 3 x 8 = 72 bits / 8 = 9 bytes 1.6 Digital Image Representation
  • 109. Calculate image size The image on the right has an image resolution of 600x600 and a bit depth of 8 (8 bits for each red, green, and blue. What is its size in MiB? Formula: Image Resolution x Colour Depth 600 x 600 x 8 x 3 = 8640000 bits 1.6 Digital Image Representation
  • 110. Calculate image size The image on the right has an image resolution of 600x600 and a bit depth of 8 (8 bits for each red, green, and blue. What is its size in MiB? Formula: Image Resolution x Colour Depth 600 x 600 x 8 x 3 = 8640000 bits / 8 = 1080000 bytes = 1054 KiB = 1.03 MiB 1.6 Digital Image Representation
  • 111. Bitmap • A bitmap file includes pixel data and a header describing its construction, causing the file size to exceed the graphic size. 1.6 Digital Image Representation
  • 112. Vector graphic or bitmap • Opt for vector graphics in architectural, engineering, or manufacturing design diagrams. • Convert vector graphics to bitmaps before printing via laser or inkjet. • Digital cameras generate bitmaps by default. • Choose bitmap files for embedding images in documents, publications, or web pages. 1.6 Digital Image Representation
  • 113. 1.7 Data Compression Methods Why is compression needed? Bigger files demand greater storage and significantly slower transmission or download rates. Lossless compression Lossy compression • File size shrinks without losing data • The process is reversible to restore the original file. • File size decreases with partial information loss • Complete restoration of the original file isn't possible.
  • 114. Lossless Compression An effective compression tool identifies compressible patterns in files and is often tailored for specific file types. We will learn two compression methods here. 1.7 Data Compression Methods
  • 115. A compression method that encodes repeated byte values by specifying their count and value. Eg. It works well with a bitmap file. Run-length encoding 10101101 10101101 10101101 10101101 10111101 10111101 10111101 10111101 10101100 10101100 10101100 10101100 10101101 10101101 10101101 10101101 10111101 10111101 10111101 10111101 10101100 10101100 10101100 10101100 Before RLE 1.7 Data Compression Methods
  • 116. A compression method that encodes repeated byte values by specifying their count and value. Eg. It works well with a bitmap file. Run-length encoding 10101101 10101101 10101101 10101101 10111101 10111101 10111101 10111101 10101100 10101100 10101100 10101100 10101101 10101101 10101101 10101101 10111101 10111101 10111101 10111101 10101100 10101100 10101100 10101100 Before RLE 10101101 00000100 (4) 10111101 00000100 (4) 10101100 00000100 (4) After RLE 1.7 Data Compression Methods
  • 117. It also works well with repeated text Run-length encoding 01100001 01100001 01100001 01100001 01100010 01100010 01100010 01100010 Before RLE (ASCII) aaaa bbbb 1.7 Data Compression Methods
  • 118. It also works well with repeated text Run-length encoding 01100001 01100001 01100001 01100001 01100010 01100010 01100010 01100010 Before RLE (ASCII) 01100001 00000100 (4) 01100010 00000100 (4) After RLE aaaa bbbb 1.7 Data Compression Methods
  • 119. Principle: Analyzing text to identify common characters, which are assigned shorter codes than one-byte coding. Eg. Huffman Encoding Count the frequency of each character in the text: • 'a': 5 times • 'b': 2 times • 'r': 2 times • 'c': 1 time • 'd': 1 time Step 1 abracadabra 1.7 Data Compression Methods
  • 120. a 0 b 10 r 110 c 1110 d 1111 Principle: Analyzing text to identify common characters, which are assigned shorter codes than one-byte coding. Eg. Huffman Encoding Count the frequency of each character in the text: • 'a': 5 times • 'b': 2 times • 'r': 2 times • 'c': 1 time • 'd': 1 time Step 1 abracadabra Create Huffman coding Step 2 1.7 Data Compression Methods
  • 121. a 0 b 10 r 110 c 1110 d 1111 Principle: Analyzing text to identify common characters, which are assigned shorter codes than one-byte coding. Eg. Huffman Encoding Count the frequency of each character in the text: • 'a': 5 times • 'b': 2 times • 'r': 2 times • 'c': 1 time • 'd': 1 time Step 1 abracadabra Create Huffman coding Step 2 Step 3 Replace each character with its assigned code to get the compressed text: 01001101010011010101001001001000 1.7 Data Compression Methods
  • 122. Lossy Compression Lossy compression is applicable when less crucial sound or image details can be altered without significant human perception. Sound • Technique 1: Capitalise on the infrequent change of successive sampled values. • Technique 2: Convert individual sample amplitudes to amplitude difference. Compression is achieved by using a lower sample resolution to store the differences. 1 2 3 4 5 6 7 8 9 10 time 1 2 3 4 5 6 7 8 amplitude 1.7 Data Compression Methods
  • 123. Lossy Compression Lossy compression is applicable when less crucial sound or image details can be altered without significant human perception. Image • Establish a coding scheme with reduced colour depth. Before compression After compression (Extreme) 1.7 Data Compression Methods