Chapter 1 : Data Representation
[Why Computers Use Binary]
Why does data have to be converted to
binary to be processed by a computer?
● Data is processed in a computer using logic gates that only have two
states
● The binary number system only has two digits (1/0), which means each
digit can represent a different state (1 = on, 0 = off)
● All data must be converted to binary before a computer can understand
and process it
● Converting data to binary allows computers to process it at an incredible
speed, perform complex calculations and store vast amounts of data
efficiently
● Secondary storage is a great example of the process
○ Magnetic hard drives use North and South polarity to represent a 1
or a 0
○ In Optical disks, light hitting a flat area (land) is interpreted as a 1
and light hitting a bump (pit) is interpreted as a 0
● Take an example of driving a car
○ When driving a car the accelerator pedal is used to increase the
cars speed
○ If a car was accelerating from 50mph to 100mph the increase
would be gradual
○ In a computer system, the car is doing either 50mph (0) or 100mph
(1), there is no in-between
○ Trying to change the computer system so that it has more options
would be less efficient and require more complex parts for the
computer to understand
[The Denary, Binary & Hexadecimal
Number Systems]
What is denary?
● Denary is a number system that is made up of 10 digits (0-9)
● Denary is referred to as a base-10 number system
● Each digit has a weight factor of 10 raised to a power, the rightmost
digit is 1s (100), the next digit to the left 10s (101) and so on
● Humans use the denary system for counting, measuring and performing
maths calculations
● Using combinations of the 10 digits we can represent any number
● In this example, (3 x 1000) + (2 x 100) + (6 x 10) + (8 x 1) = 3268
● To represent a bigger number we add more digits
What is binary?
● Binary is a number system that is made up of two digits (1 and 0)
● Binary is referred to as a base-2 number system
● Each digit has a weight factor of 2 raised to a power, the rightmost digit
is 1s (20), the next digit to the left 2s (21) and so on
● Each time a new digit is added, the column value is multiplied by 2
● Using combinations of the 2 digits we can represent any number
● In this example, Binary 1100 = (1 x 8) + (1 x 4) = 12
● To represent bigger numbers we add more binary digits (bits)
16,3 8,19 4,09 2,04 1,02 51 25 128 64 32 16 8 4 2 1 0
84 2 6 8 4 2 6
215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20
What is hexadecimal?
● Hexadecimal is a number system that is made up of 16 digits, 10 numbers
(0-9) and 6 letters (A-F)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7 8 9 A B C D E F
● Hexadecimal is referred to as a base-16 number system
● Each digit has a weight factor of 16 raised to a power, the rightmost
digit is 1s (16^0), the next digit to the left 16s (16^1)
Denary Binary Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
(Note: please revise all the conversions from the book)
[Uses of Hexadecimal]
Why is hexadecimal used?
● In Computer Science hexadecimal is often preferred when working with
large values
● It takes fewer digits to represent a given value in hexadecimal than in
binary
○ 1 hexadecimal digit corresponds 4 bits (one nibble) and can
represent 16 unique values (0-F)
● It is beneficial to use hexadecimal over binary because:
○ The more bits there are in a binary number, the harder it makes
for a human to read
○ Numbers with more bits are more prone to errors when being
copied
Examples of where hexadecimal can be seen:
○ MAC addresses
○ Colour codes
○ URLs
MAC addresses
● MAC address are covered here in full
● A typical MAC address consists of 12 hexadecimal digits, equivalent to 48
digits in in binary
○ AA:BB:CC:DD:EE:FF
○ 10101010:10111011:11001100:11011101:11101110:11111111
● Writing down or performing calculations with 48 binary digits makes it
very easy to make a mistake
Colour codes
● A typical hexadecimal colour code consists of 6 hexadecimal digits,
equivalent to 24 digits in binary
○ #66FF33 (green)
○ 01000010:11111111:00110011
URL's
● A URL can only contain standard characters (a-z and A-Z), numbers (0-9)
and some special symbols which is enough for basic web browsing
● If a URL needs to include a character outside of this set, they are
converted into a hexadecimal code
● Hexadecimal codes included in a URL are prefixed with a % sign
[Adding Positive 8-bit Binary Integers]
(Note: please refer to book for revision of this)
[Overflow & Binary Addition]
What is an overflow error?
● An overflow error occurs when the result of a binary addition exceeds
the available bits
● For example, if you took binary 11111111 (255) and tried to add 00000001
(1) this would cause an overflow error as the result would need a 9th bit
to represent the answer (256)
[Binary Shifts]
What is a logical binary shift?
● A logical binary shift is how a computer system performs basic
multiplication and division on non-negative values (0 and positive numbers)
● Binary digits are moved left or right a set number of times
● A left shift multiplies a binary number by 2 (x2)
● A right shift divides a binary number by 2 (/2)
● A shift can move more than one place at a time, the principle remains the
same
● A left shift of 2 places would multiply the original binary number by 4
(x4)
How do you perform a logical left shift of 1?
(Note : left shifts are towards the left and this multiplies it by 2 the
original value if you want to multiple it by 4 you perform two logical left
shifts)
How do you perform a logical right shift of
1?
(Note : right shifts are towards the right and this divides it by 2 the
original value if you want to divide by 4 you perform two logical right
shifts)
Overflow in binary shifts
● Overflow happens when a 1 is shifted out of the most significant bit
(MSB) on the left in a logical left shift
● This means important data is lost, which can seriously change the
number’s value
[Two's Complement]
What is two's complement?
● In IGCSE Computer Science, two's complement is a method of using
signed binary shifts to represent negative numbers
● Using two's complement the left most bit is designated the most
significant bit (MSB)
● In two’s complement, if the MSB is 1, it represents a negative number
● In 8-bit, the MSB column has a weight of -128, while the remaining
columns keep their positive values
-128 64 32 16 8 4 2 1
1 1 1 1 1 1 1 1 = -1
●
In the example above, to find the value, add together the column values
where there is a 1
● Here, all columns are 1, so the sum is -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 =
-1
● The two's complement representation of -1 is 11111111
Quick two's complement conversion
● To represent -76
● Write out the positive version of the number
128 64 32 16 8 4 2 1
0 1 0 0 1 1 0 0 = 76
●
Starting from the least significant bit (right most column), copy out the
binary values up to and including the first 1
-128 64 32 16 8 4 2 1
1 0 0
●
For the remaining digits, invert them (0s to 1s/1s to 0s)
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 0
●
-128 + 32 + 16 + 4 = -76
● The two's complement representation of -76 is 10110100
[Character Sets]
What is a character set?
● A character set is all the characters and symbols that can be
represented by a computer system
● Each character is given a unique binary code
● Character sets are ordered logically, the code for ‘B’ is one more than the
code for ‘A’
● A character set provides a standard for computers to communicate and
send/receive information
● Without a character set, one system might interpret 01000001
differently from another
● The number of characters that can be represented is determined by the
number of bits used by the character set
● Two common character sets are:
○ American Standard Code for Information Interchange (ASCII)
○ Universal Character Encoding (UNICODE)
[ASCII]
What is ASCII?
● ASCII is a character set and was an accepted standard for information
interchange
● ASCII uses 7 bits, providing 27 unique codes (128) or a maximum of 128
characters it can represent
● ASCII only represents basic characters needed for English, limiting its
use for other languages
Extended ASCII
● Extended ASCII uses 8 bits, providing 256 unique codes (28 = 256) or a
maximum of 256 characters it can represent
● Extended ASCII provides essential characters such as mathematical
operators and more recent symbols such as ©
Limitations of ASCII & extended ASCII
● ASCII has a limited number of characters which means it can only
represent the English alphabet, numbers and some special characters
○ A, B, C, ………, Z
○ a, b, c ,.............,z
○ 0, 1, 2,........, 9
○ !, @, #, …..
● ASCII cannot represent characters from languages other than English
● ASCII does not include modern symbols or emojis common in today's
digital communication
[UNICODE]
What is UNICODE?
● UNICODE is a character set and was created as a solution to the
limitations of ASCII
● UNICODE uses a minimum of 16 bits, providing 216 unique codes (65,536)
or a minimum of 65,536 characters it can represent
● UNICODE can represent characters from all the major languages around
the world
ASCII vs UNICODE
ASCII UNICODE
Number of bits 7-bits 16-bits
Number of 128 characters 65,536 characters
characters
Uses Used to represent characters Used to represent characters
in the English language. across the world.
Benefits It uses a lot less storage It can represent more
space than UNICODE. characters than ASCII.
It can support all common
characters across the world.
It can represent special
characters such as emoji's.
Drawbacks It can only represent 128 It uses a lot more storage
characters. space than ASCII.
It cannot store special
characters such as emoji's.
[How Sound is Sampled & Stored]
How is sound sampled & stored?
● Measurements of the original sound wave are captured and stored as binary
on secondary storage
● Sound waves begin as analogue and for a computer system to understand
them they must be converted into a digital form
● This process is called Analogue to Digital conversion (A2D)
● The process begins by measuring the amplitude of the analogue sound wave
at a point in time, called samples
● Each measurement (sample) generates a value which can be represented in
binary and stored
● Using the samples, a computer is able to create a digital version of the
original analogue wave
● The digital wave is stored on secondary storage and can be played back at
any time by reversing the process
● In this example, the grey line represents the digital wave that has been
created by taking samples of the original analogue wave
● In order for the digital wave to look more like the analogue wave the sample
rate and bit depth can be changed
[Sample Rate & Sample Resolution]
What is sample rate?
● Sample rate is the amount of samples taken per second of the analogue wave
● Samples are taken each second for the duration of the sound
● The sample rate is measured in Hertz (Hz)
● 1 Hertz is equal to 1 sample of the sound wave
In this example you can see that the higher the sample rate, the closer to the
original sound wave the digital version looks
● The sampling rate of a typical audio CD is 44.1kHz (44,100 Hertz or 44,100
samples per second)
● Using the graphic above helps to answer the question, “Why does telephone
hold music sound so bad?”
What is sample resolution?
● Sample resolution is the number of bits stored per sample of sound
● Sample resolution is closely related to the colour depth of a bitmap image,
they measure the same thing in different contexts
What effect do sample rate and sample
resolution have?
Sample rate Sample resolution
High Low High Low
Playback quality ⇑ ⇓ ⇑ ⇓
File size ⇑ ⇓ ⇑ ⇓
[Bitmap Images]
What is a bitmap?
● A bitmap image is made up of squares called pixels
● A pixel is the smallest element of a bitmap image
● Each pixel is stored as a binary code
● Binary codes are unique to the colour in each pixel
● A typical example of a bitmap image is a photograph
● The more colours and more detail in the image, the higher the quality of
the image and the more binary that needs to be stored
[Resolution & Colour Depth]
What is resolution?
● Resolution is the total amount of pixels that make up a bitmap image
● The resolution is calculated by multiplying the height and width of the
image (in pixels)
● In general, the higher the resolution the more detail in the image (higher
quality)
● Resolution can also refer to the total amount of pixels horizontally in a
display, such as:
○ Computer monitors - 1440p means 1440 pixels horizontally
compared to 4K which is 3840 pixels (roughly 4 thousand)
○ TVs - HD (high definition) channels have a resolution of 1080p,
1080 pixels horizontally compared to newer UHD (ultra high
definition) channels with 3840 pixels (4K)
○ YouTube - The quality button allows a user to change the video
playback resolution from 144p (144 pixels horizontally) up to 4K
What is colour depth?
● Colour depth is the number of bits stored per pixel in a bitmap image
● The colour depth is dependent on the number of colours needed in the
image
● In general, the higher the colour depth the more detail in the image
(higher quality)
● In a black & white image the colour depth would be 1, meaning 1 bit is
enough to create a unique binary code for each colour in the image
(1=white, 0=black)
● In an image with a colour depth of 2, you would have 00, 01, 10 & 11
available binary codes, so 4 colours
● As colour depth increases, so does the amount of colours available in an
image
● The amount of colours can be calculated as 2n (n = colour depth)
Colour Depth Amount of Colours
1 bit 2 (B&W)
2 bit 4
4 bit 16
8 bit 256
24 bit 16,777,216 (True Colour)
What is the impact of resolution and colour
depth?
● As the resolution and/or colour depth increases, the bigger the size of
the file becomes on secondary storage
● The higher the resolution, the more pixels are in the image, the more bits
are stored
● The higher the colour depth, the more bits per pixel are stored
● Striking a balance between quality and file size is always a consideration
[Units of Data Storage]
What are units of data storage?
● A unit of data is a term given to describe different amounts of binary
digits stored on a digital device
● These are the units you need to know for IGCSE:
Unit Symbol Value
Bit b 1 or 0
Nibble 4b
Byte B 8b
Kibibyte KiB 1,024 B (210)
Mebibyte MiB 1,024 KiB (220)
Gibibyte GiB 1.024 MiB (230)
Tebibyte TiB 1,024 GiB (240)
Megabyte vs Mebibyte
● 1 kibibyte (1KiB) = 1024 bytes (1024 B) - binary prefixes (to the power of
2)
● 1 kilobyte (1KB) = 1000 bytes (1000 B) - decimal prefixes (to the power of
10)
Converting between units
● It is often a requirement of the exam to be able to convert between
different units of data, for example bytes to mebibytes (larger) or
kibibytes to bytes (smaller)
● This process involves division, moving up in size of unit and multiplication,
moving down in size of unit
● When dealing with all units bigger than a byte we use multiples of 1024
(210)
● For example, 2000 kibibytes in mebibytes would be 2000 / 1024 = 1.95
MiB and 2 tebibytes in gibibytes would be 2 * 1024 = 2048 GiB
● When dealing with bits and bytes the same process is used with the value
8 as there are 8 bits in a byte
● For example, 24 bits in bytes would be 24 / 8 = 3 B and 10 bytes in bits
would be 10 * 8 = 80 b
Unit
Multiply by 8 ⇑ Bit Divide by 8 ⇓
Byte
Multiply by 1024 ⇑ Kibibyte Divide by 1024 ⇓
Mebibyte
Gibibyte
Tebibyte
[Calculating File Sizes]
How do you calculate the size of a bitmap
image?
● Calculating the size of a bitmap image can be carried out with either of
the following formulas:
○ Resolution x colour depth
○ Image width x image height x colour depth
Example
Image Files
(Resolution) x (Colour Depth)
Size of bitmap image =
Resolution 250,000 Resolution = width x height
Colour Depth 24 bits (3 bytes) 24 bits = 3 bytes
250,000 x 24 = 6,000,000 bits
(bit to bytes) /8 750,000 bytes
(bytes to KiB) /1024 732 KiB
250000 x 3 = 750,000 bytes
(bytes to KiB) /1024 732 KiB
OR
Image Files
(Image width) x (Image height) x (Colour Depth)
Size of bitmap image =
Image width 500
Image height 500
Colour Depth 24 bits 24 bits = 3 bytes
(500 x 500 x 24) = 6,000,000 bits
(bit to bytes) /8 750,000 bytes
(bytes to KiB) /1024 732 KiB
(500 x 500 x 3) = 750,000 bytes
(bytes to KiB) /1024 732 KiB
[How do you calculate the size of a sound file?]
● Calculating the size of a sound file is carried out with the following formula:
○ Sample rate x duration x sample resolution
Example
Sound Files
(Sample Rate) x (Duration in seconds) x (Sample Resolution)
Size of sound file =
Sample rate 100 Samples per second
Duration 60 Seconds
Sample resolution 24 Number of bits stored per
sample
100 x 60 x 24 = 144,000 bits
(bit to bytes) /8 18,000 bytes
(bytes to KiB) /1024 18 KiB
[The Need For Compression]
What is compression?
● Compression is reducing the size of a file so that it takes up less space on
secondary storage
● The impact of compression is:
○ Less storage space required
○ Less bandwidth required
○ Shorter transmission time
● Compression can be achieved using two methods, lossy and lossless
[Lossy Compression]
What is lossy compression?
● Lossy compression is when data is lost in order to reduce the size on
secondary storage
● Lossy compression is irreversible
● Lossy can greatly reduce the size of a file but at the expense of losing
quality
● Lossy is only suitable for data where reducing quality is acceptable, for
example images, video and sound
● In photographs, lossy compression will try to group similar colours
together, reducing the amount of colours in the image without
compromising the overall quality of the image
● In the images below, lossy compression is applied to a photograph and
dramatically reduces the file size
● Data has been removed and the overall quality has been reduced, however
it is acceptable as it is difficult to visually see a difference
● Lossy compressed photographs take up less storage space which means
you can store more and they are quicker to share across a network
[Lossless Compression]
What is lossless compression?
● Lossless compression is when data is encoded in order to reduce the size
on secondary storage
● Lossless compression is reversible, the file can be returned to its original
state
● Lossless can reduce the size of a file but not as dramatically as lossy
● Lossless can be used on all data but is more suitable for data where a loss
in quality is unacceptable, for example documents
● In a document, lossless compression algorithms such as run length
encoding (RLE) can be used to analyse the contents looking for patterns
and repetition.
What is run length encoding?
● Run length encoding (RLE) is a form of lossless data compression that
condenses identical elements into a single value with a count
● For a text file, "AAAABBBCCDAA" is compressed to "4A3B2C1D2A"
● The string has four 'A's, followed by three 'B's, two 'C's, one 'D', and
two 'A's
● RLE is used in bitmap images to compress sequences of the same colour
● For example, a line in an image with 5 red pixels followed by 3 blue pixels
could be represented as "5R3B"
Compression pictures :
Lossless file formats
● In the image above, lossless compression is automatically applied to
document formats such as DOCX and PDF with a different rate of
success
● When you open a lossless compressed document the decompression
process reverses the algorithms and returns the data back to its original
state
● Lossless compressed documents take up less storage space which means
you can store more and they are quicker to share across a network