Data Representation & Storage
Data Representation & Storage
1 2
3 4
Data Representation & Storage
Units
• A binary digit is known as a bit. A bit is the smallest unit of data a
Analogue data and digital data
computer can use.
Analogue data is a real-life signal that can vary greatly in value.
• Eight bits are known as a byte. A byte is significant in that a single
character can be represented in binary in eight bits - one byte. Examples include:
• sound waves
• Four bits or half a byte is known as a nibble. • pressure
• temperature
• To be able to reference large numbers of 0s and 1s, the binary unit
system is used: • Digital data is binary data which represents analogue data. Computers
work with digital data. Analogue data must be converted to digital before a
computer can use it.
• A device known as an analogue-to-digital convertor (ADC) is used to
generate digital data from analogue signals. In the same way, a digital
signal can be converted back to an analogue signal using a digital-to-
analogue convertor (DAC).
5 6
7 8
Data Representation & Storage
Hexadecimal
• In computer science, different • Hexadecimal is useful because large
number bases are used: numbers can be represented using fewer
digits.
• denary is base 10, which has ten • Additionally, hexadecimal is easier to
units (0-9) understand than binary. Programmers
• binary is base 2 , which has two often use hexadecimal to represent binary
units (0-1) values as they are simpler to write and
check than when using binary.
• hexadecimal, also known as hex, is
the third commonly used number
system. The digits 0, 1, 2, 3, 4, 5, 6, When data is stored or transmitted, its ASCII or Unicode number is used, not the character itself.
For example, the word "Computer" would be represented as:
7, 8 and 9 and the capital letters A, 1000011 1101111 1101101 1110000 1110101 1110100 1100101 1110010
B, C, D, E and F. Question
What would this message say?
1001000 1100101 1101100 1101100 1101111 0100001
Hello!
9 10
• Many ancient cultures developed the counting system that we use • Computers obviously don't have fingers,
but instead use tiny switches called
today, known as the decimal system. transistors that allow electricity to
• It allows us to use ten values and it is likely that this common be on or off in a circuit.
approach was developed because of the fact humans have ten • These circuits are combined to
represent data and the two states
fingers/digits to count with. of on or off are represented as 1 or 0.
• You may have also heard this system referred to as denary or base- • The binary system is known as a
10. ‘base 2’ system. This is because:
• there are only two digits to select
from (1 and 0)
• when using the binary system, data
is converted using the power of two.
11 12
Data Representation & Storage
Understanding denary
To sum up • People use the denary (or decimal) number system in their day-to-
day lives. This system has 10 digits that we can use: 0, 1, 2, 3, 4, 5, 6,
• Combinations of 1s and 0s can be 7, 8 and 9.
used by a computer to represent • The value of each place value is calculated by multiplying by 10 (ie by
any type of information (e.g. the power of 10). The first few place values look like this:
numbers, text, images, sound,
program instructions).
13 14
15 16
Data Representation & Storage
17 18
Binary to denary
• To convert a binary number to denary, start by writing out the binary
place values. In denary, the place values are 1, 10, 100, 1000, etc –
each place value is 10 times bigger than the last. For example:
• In binary, each place value is 2 times bigger than the last (ie increased
by the power of 2). The first few binary place values look like this: The top row shows the place values - starting at 1 (on the right) each place value is 2 times the
previous (2, 4, 8, 16 etc). The bottom row holds the binary digits (0 or 1).
The table shows the binary number 10100110.
To convert the binary number to denary, we just need to write down the place value of each binary
1 digit, and add them all up. 128 + 32 +4 + 2 equals 166. That is the denary equivalent of binary
10100110.
19 20
Data Representation & Storage
21 22
3.Add the numbers in the binary place value row that have a 1 in the
binary row.
23 24
Data Representation & Storage
Question 2 Question 3
What would the binary number 1001 0011 represent in Denary? What would the binary number 101100101 represent in Denary?
Hint: In a base-2 system, each place value increases by a power of 2. The first place
value is 20 (1), the second is 21 (2), the third is 22 (4), the fourth is 23 (8) and so on.
We could represent 8 bits (one byte) of data using the table below. Answer
Answer
• This binary number represents 128 + 16 + 2 + 1. Or • By adding together ALL the decimal number values from right to left at the
positions that are represented by a “1” gives
27 + 24 + 21 + 20. us: (256) + (64) + (32) + (4) + (1) = 35710 or three hundred and fifty seven as a
• The sum of these values is 147. decimal number.
• Therefore, the 8-bit binary number 1001 0011 represents 147 in denary.
25 26
27 28
Data Representation & Storage
01010101 = 00111011=
29 30
31 32
Data Representation & Storage
33 34
35 36
Data Representation & Storage
Method two - convert denary to binary The binary equivalent of 100 is 1100100.
To convert decimal to binary numbers,
Another method to convert denary to Starting with the least significant bit proceed with the steps given below:
binary is to divide the number by 2 (LSB), mark down the remainders
and mark down the remainder (1 or • 1010011 Step 1: Divide the given decimal number by
0). “2”, where it provides the result along with the
• As there are only seven digits in
Worked example: Denary number 83 this binary number, you can make it remainder.
• 83÷2=41 (remainder 1) into an 8-bit binary number by Step 2: If the given decimal number is even,
'padding' the result with the then the result will be a whole number, and it
• 41÷2=20 (remainder 1) provides the remainder with “0.”
required number of 0s on the left.
• 20÷2=10 (remainder 0) Step 3: If the given decimal number is odd,
• This produces the 8-bit binary then the result is not appropriately divided,
• 10÷2=5 (remainder 0) number 0101 0011, equivalent to and it provides the remainder with “1”.
• 5÷2=2 (remainder 1) 83 in denary (64 + 16 + 2 + 1). Step 4: By placing all the remainders in order
• 2÷2=1 (remainder 0) in such a way, the Least Significant Bit (LSB) at
the top and Most Significant Bit (MSB) at the
• 1÷2=0 (remainder 1) bottom, the required binary number will be
obtained.
37 38
is
1001001102 Dividend Remainder Dividend Remainder
2/2 = 1 0 3/2 = 1 1
29410 =1001001102
1/2 = 0 1 1/2 = 0 1
39 40
Data Representation & Storage
Binary addition is (in some ways) even easier, as there are only a few cases
we need to consider:
41 42
Binary addition
• When two numbers are added together Example - adding 01 + 10
in denary, we take the first number, add • 1+0=1
the second number to it, and get an • 0+1=1
answer. For example, 1 + 2 = 3.
• When we add two binary numbers
together the process is different. Result in binary: 11 (which is denary 3)
• There are four rules that need to be Example - adding 01 + 101
followed when adding two binary • 1 + 1 = 0, carry 1
numbers. These are: • 1+0+0=1
• 0+0=0 • 0+1=1
• 1+0=1
• 1 + 1 = 10 (The 1 is carried into the next
column on the left)
• 1 + 1 + 1 = 11 (The 1 is carried into the Result in binary: 110 (which is denary 6)
next column on the left)
43 44
Data Representation & Storage
45 46
47 48
Data Representation & Storage
• All data on a computer system is • A bitmapped graphic (also called a • A pixel represents the smallest
represented using binary patterns, bitmap image) is made up of a grid element of a bitmapped graphic: a
which are sequences of 1s and 0s. of pixels. single colour. As all data in a
• In order to represent an image, • A pixel (short for ‘picture element’) computer is stored in 1s and 0s,
one method is to store it as if it is the smallest element in an each colour needs to have a binary
were a grid of coloured squares, image. code assigned to it.
with each colour represented by a • If you magnify an image, you will • For example, the black-and-grey
unique binary pattern. see that it is made up of these tiny image shown in Figure 1 can be
• The image dimensions and the elements. represented by using just one bit
number of colours used are factors per pixel, by assigning a 0 to each
that affect the size of the image black pixel and a 1 to each grey
file. pixel.
Figure 1: A one-bit black and grey picture
49 50
• Bitmap images that require only • Figure 2: One-bit images can be • If an image needs more than two
two colours can be represented used for more than just black colours, you will need more bits
by using just one bit per pixel. and white per pixel.
• The image (Figure 2) uses two • For example, with 2 bits, you can
colours and has been created by have 2 × 2 = 4 different bit
assigning a 0 to each orange patterns, and so you can
pixel and a 1 to each pink pixel. represent four different colours.
• As you can see in the table each
bit-pattern is assigned a colour.
51 52
Data Representation & Storage
53 54
• Image resolution refers to the • Note that the term 'image • The number of bits used per pixel is called • When an image has a width of 8 pixels
clarity of an image as it appears on resolution' is sometimes used to the colour depth. The greater the colour depth, and a height of 8 pixels, with a colour
a screen or on paper. describe the size of a bitmapped the more colours are available for an image. depth of 4 bits, the calculation is:
• When you zoom in to a bitmap graphic in pixels. • The image resolution is the size of a bitmapped • Calculate total bits: 8 × 8 × 4 = 256 bits
graphic in pixels. It is calculated by multiplying
image, the pixels are stretched into • The size in pixels is calculated by Example
the width (in pixels) by the height (in pixels) of
larger blocks. That’s why bitmap multiplying the width (in pixels) by an image. • What is the file size of a bitmapped
images appear in poor quality the height (in pixels) of the image. • To find the size of an image file, you multiply
graphic that is 6 × 4 pixels and has a
when you enlarge them too much. the resolution of the image by the colour
colour depth of 2 bits?
• Image resolution can be expressed depth: image file size (in bits) = width (in Give your answer in bits.
pixels) × height (in pixels) × colour depth
as the number of pixels that an • Calculate total bits: 6 × 4 × 2 = 48 bits
image contains per inch (e.g. 300 • This means that the size of an image file will
ppi (pixels per inch)). increase if either the colour depth or the image
resolution increases.
55 56
Data Representation & Storage
Units of data storage Difference between the two units of data storage system
• Historically, storage capacity was expressed using the metric The differences between the two systems are shown below, pay close
attention to the Notation:
prefixes of kilo (1,000), mega (1,000,000), etc.
• Since 1998 there has been a move towards using the special
prefixes developed to more accurately represent binary values
(as per the International System of Units (SI) definition).
• For example, a kibibyte is equal to 1,024 bytes, whereas a
kilobyte is equal to 1,000 bytes.
57 58
When an image has a width of 240 When an image has a width of 1920 • What is the file size of a Working out:
pixels and a height of 300 pixels, with pixels and a height of 1080 pixels,
a colour depth of 4 bits, the with a colour depth of 24 bits, the bitmapped graphic that is 800 × • Calculate total bits: 800 × 800
calculation is: calculation is: 800 pixels and has a colour × 4 = 2,560,000 bits
1.Calculate total bits: 240 × 300 × 4 1.Calculate total bits: 1080 × 1920 × depth of 4 bits?
= 288,000 bits 24 = 49,766,400 bits Give your answer in kB. Assume • Convert bits to bytes:
2.Convert bits to bytes: 288,000 / 8 = 2.Convert bits to bytes: 49,766,400 / that 1kB = 1000 bytes. 2,560,000 / 8 = 320,000 bytes
36,000 bytes 8 = 6,220,800 bytes
• Convert bytes to kilobytes:
3.Convert bytes to kilobytes: 36,000 3.Convert bytes to kilobytes:
/ 1000 = 36kB 6,220,800 / 1000 = 6,220.8kB 320,000 / 1000 = 320kB
4.Convert kilobytes to megabytes:
6,220.8 / 1000 = 6.2208MB
59 60
Data Representation & Storage
61 62
63 64
Data Representation & Storage
65 66
67 68
Data Representation & Storage
69 70
71 72
Data Representation & Storage
Representing sound
• Computers work in binary. All data must be converted into binary in order
for a computer to process it. Sound is no exception. To do this, sound is
captured - usually by a microphone - and then converted into a digital
signal.
• Sound is the continual vibration of air particles and is an analogue signal.
Therefore, we need to convert sound into binary to be able to process and
store it using a computer.
• A sound card translates between the outside world's analogue information
and a computer's digital information.
• It uses an analogue to digital convertor (ADC) to change sound into a digital
format the computer can understand, and a digital to analogue convertor
(DAC) to change digital information into sound that you can hear.
73 74
75 76
Data Representation & Storage
Just as with images, the higher the bit depth, the more accurately a sound can be recorded, but the larger the file
size.
How many possible values would an 8-bit audio sample have responses?
The maximum value that could be represented by an 8 bit number is 255, so the range would be 0—255 (256
values).
Typical bit depths are 16 bit and 24 bit.
77 78
79 80
Data Representation & Storage
81 82
Amplitude controls how loud the sound is and the Wave traces
frequency controls the pitch. Example: • To record or analyse a sound, scientists and musicians use a microphone to turn the sound into an
electrical signal.
• The electrical signal can then be displayed on a device called an oscilloscope and it produces a
graph called a wave trace.
83 84
Data Representation & Storage
85 86
87 88
Data Representation & Storage
89 90
Lossy compression
Compression • With lossy compression, some data is removed and Note: An audio file can be compressed by reducing
discarded, thereby reducing the overall amount of the bit depth of the samples.
data and the size of the file. Another technique discards very quiet sounds that a
• Modern computer processing often generates files of very large sizes. • An image can be compressed by reducing its colour
listener is unlikely to notice, especially in a louder part of
a song. This approach reduces the size of the audio file
For example, audio files often run to megabytes (MB), while high- depth. This reduces the range of colours that the while retaining as much audio quality as possible.
definition video can be gigabytes (GB) in size. Such files require lots of image contains. In practice, this results in an
averaging of shades of colours. For example, a very
storage space, and, because of their size, are difficult to transmit. light shade of green could be averaged with a not
These problems can be overcome by using compression. so light shade - the very light shade might be
discarded, and the pixels affected by it re-coloured
• There are two types of compression that can be applied to files: with the darker shade.
• lossy compression Various lossy standards exist:
• lossless compression • the JPEG file format works on this principle, which
is why JPEG files tend to be smaller in size
• the MPEG file format compresses audio and video,
making it more suitable for streaming media
• MP3 is a lossy format for audio, including music
91 92
Data Representation & Storage
Lossless compression
• There are some files that • With lossless compression, files are
programmers do not want to lose reduced in size without the loss of
data from. For example: data. However, lossless compression
does not usually achieve the same file
• text files size reduction as lossy compression.
• spreadsheets Various lossless standards exist, eg:
• financial records • PDF allows lossless compression of
• emails text documents
• GIF is a lossless image file format
93 94
95 96
Data Representation & Storage
Storage
• Computer users need to be able to store programs and data when the power is
Common types of secondary storage
switched off. Secondary storage is used to hold data and programs on physical
devices when the computer is not in use. • Secondary storage devices are generally separated into three types:
Secondary storage • magnetic storage devices, such as hard disk drives
• Computers use primary memory such as random access
memory (RAM) and cache(A piece of temporary memory) to hold data that is • optical storage devices, such as CD, DVD and Blu-ray discs
being processed. However, this type of memory is volatile, which means it loses
its contents when the computer is switched off. • solid state storage devices, such as solid state drives and USB
• Secondary storage is non-volatile, long-term storage. It is used to keep programs memory sticks
and data indefinitely. Without secondary storage all programs and data would be
lost the moment the computer is switched off.
• There are many forms of secondary storage, and each type of secondary storage
device has its own characteristics. Because all devices are different, some are
more suited to certain applications than others.
Note: Not all computers require secondary storage. Embedded computers, such as
those found in a digital watch or central heating system, do not need to store data
when the power is turned off. The instructions needed to run them are stored
in ROM and any user data is held in RAM.
97 98
101 102
103 104