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
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
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
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
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
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
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
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
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
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