Chapter 1 Data Representation
Chapter 1 Data Representation
A DMC 2023
Data representation
✓ Number systems
Binary, denary and hexadecimal systems
Each time a 1-value appears in a binary number column, the column value (heading) is added to a
total.
Example
Example
Method 1
The denary number 142 is made up of 128 + 8 + 4 + 2 (that is, 142 – 128 = 14; 14 – 8 = 6; 6 – 4 = 2; 2 – 2 = 0.
In each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached.
1
G10 Computer Science P1 Data Representation N.A DMC 2023
Method 2
• Starting from the right and moving left, split the binary number into groups of 4 bits.
• If the last group has less than 4 bits, then simply fill in with 0s from the left.
• Take each group of 4 bits and convert it into the equivalent hexadecimal digit.
2
G10 Computer Science P1 Data Representation N.A DMC 2023
Example
First split this up into groups of 4 bits (nibble), starting from the right-hand side:
=11 i.e B
= 14 i.e. E
=1
3
G10 Computer Science P1 Data Representation N.A DMC 2023
Example
• Involves the value headings of each hexadecimal digit; that is, 4096, 256, 16 and 1.
• Take each of the hexadecimal digits and multiply it by the heading values.
• Add all the resultant totals together to give the denary number.
Example
Add the three totals together (1024 + 80 + 10) to give the denary number:
Example
Note: Converting from hexadecimal to denary and vice versa can also be done via conversion into binary.
4
G10 Computer Science P1 Data Representation N.A DMC 2023
• Error codes
These numbers refer to the memory location of the error and are usually automatically generated by the
computer.
• MAC addresses
MAC address refers to a number which uniquely identifies a device on a network.
• IPv6 addresses
- An IPv4 address is a 32-bit number written in denary or hexadecimal form: e.g. 109.108.158.1 (or
77.76.9e.01 in hex).
- An IPv6 address is a 128-bit number broken down into 16-bit chunks, represented by a hexadecimal
number.
• HTML colour codes
- HyperText Mark-up Language (HTML) is used when writing and developing web pages.
- The different intensity of each colour (red, green and blue) is determined by its hexadecimal value.
Example 1
5
G10 Computer Science P1 Data Representation N.A DMC 2023
Example 2
126 + 62
1 0 1 1 1 1 0 0 has the equivalent denary value of 128 + 32 + 16 + 8 + 4 = 188 which is the same as 126 + 62.
Overflow
Example
• The logical shift means moving the binary number to the left or to the right.
• Each shift left is equivalent to multiplying the binary number by 2.
• Each shift right is equivalent to dividing the binary number by 2.
• As bits are shifted, any empty positions are replaced with a zero.
• If any 1-bit is lost, this will result in an error.
Example 1
The denary number 21 is 00010101 in binary. We put this into an 8-bit register:
We now shift the bits in this register one place to the left, we obtain:
6
G10 Computer Science P1 Data Representation N.A DMC 2023
Let us consider what happens if we shift the original binary number 00010101 four places left:
The left-most 1-bit has been lost. In our 8-bit register the result of 21 × 24 is 80 which is clearly incorrect. This
error is because we have exceeded the maximum number of left shifts possible using this register.
Example 2
The denary number 200 is 11001000 in binary. Putting this into an 8-bit register gives:
We now shift the bits in this register one place to the right:
The value of the binary bits is now 200 ÷ 21 i.e. 100. We can see this is correct by converting the new binary
number 01100100 to denary (64 + 32 + 4).
Example 3
a) Convert 19 and 17 into binary.
b) Carry out the binary addition of the two numbers.
c) Shift your result from part b two places left and comment on the result.
d) Shift your result from part b three places right and comment on the result.
7
G10 Computer Science P1 Data Representation N.A DMC 2023
To allow the possibility of representing negative integers we make use of two’s complement.
In two’s complement the left-most bit is changed to a negative value. For instance, for an 8-bit number, the
value 128 is now changed to −128.
This means the new range of possible numbers is: −128 (10000000) to +127 (01111111).
The left-most bit always determines the sign of the binary number.
➢ A 1-value in the left-most bit indicates a negative number and a 0-value in the left-most bit indicates a
positive number.
The following two examples show how we can write the following positive binary numbers in the two’s
complement format 19 and 4:
➢ If we wish to convert a positive denary number to the two’s complement format, we do exactly the same
as taught previously at the very start of the topic. Since the number is positive, we must have a zero in the
–128 column.
➢ Converting positive binary numbers in the two’s complement format to positive denary numbers involve
exactly the same method explained at the start of the topic. Each time a 1 appears in a column, the
column value is added to the total.
Writing negative binary numbers in two’s complement format and converting to denary
Example 1
Each time a 1 appears in a column, the column value is added to the total. So, we can see that in
denary this is: −128 + 16 + 2 + 1 = −109.
8
G10 Computer Science P1 Data Representation N.A DMC 2023
Converting negative denary numbers into binary numbers in two’s complement format
Let’s consider the number −67
Method 1
Method 2
➢ When applying two’s complement, it isn’t always necessary for a binary number to have 8 bits:
Example 1
Example 2
9
G10 Computer Science P1 Data Representation N.A DMC 2023
ASCII code – a character set for all the characters on a standard keyboard and control codes.
It does not represent characters in non-Western languages, for example Chinese characters.
Unicode – a character set which represents all the languages of the world (the first 128 characters are the
same as ASCII code)
▪ Sound
Sampling means measuring the amplitude of a sound wave. This is done using an analogue to digital converter
(ADC).
➢ Increasing the number of possible values used to represent sound amplitude also increases the
accuracy of the sampled sound.
The number of bits per sample is known as the sampling resolution (also known as the bit depth).
Sampling rate is the number of sound samples taken per second. This is measured in hertz (Hz), where 1 Hz
means ‘one sample per second’.
• The amplitude of the sound wave is first determined at set time intervals (the sampling rate).
• This gives an approximate representation of the sound wave.
• Each sample of the sound wave is then encoded as a series of binary digits.
➢ Using a higher sampling rate or larger resolution will result in a more faithful representation of the
original sound source. However, the higher the sampling rate and/or sampling resolution, the
greater the file size.
The benefits and drawbacks of using a larger sampling resolution when recording sound
10
G10 Computer Science P1 Data Representation N.A DMC 2023
Each pixel can be represented as a binary number, and so a bitmap image is stored in a computer as
a series of binary numbers.
• a black and white image only requires 1 bit per pixel – this means that each pixel can be one
of two colours, corresponding to either 1 or 0
• if each pixel is represented by 2 bits, then each pixel can be one of four colours (22 = 4),
corresponding to 00, 01, 10, or 11
• if each pixel is represented by 3 bits then each pixel can be one of eight colours (23 = 8),
corresponding to 000, 001, 010, 011, 100, 101, 110, 111.
➢ The number of bits used to represent each colour is called the colour depth.
As the number of pixels used to represent the image is increased, the size of the file will also increase.
This impacts on:
• how many images can be stored on, for example, a hard drive.
• the time to download an image from the internet or the time to transfer images from device
to device.
11
G10 Computer Science P1 Data Representation N.A DMC 2023
• A bit is the basic unit of all computing memory storage terms and is either 1 or 0.
• The byte is the smallest unit of memory in a computer.
• 1 byte is 8 bits. A 4-bit number is called a nibble – half a byte.
Memory size
For a stereo sound file, you would then multiply the result by two.
Example 1
A photograph is 1024 × 1080 pixels and uses a colour depth of 32 bits. How many photographs of this size
would fit onto a memory stick of 64 GiB?
i. Multiply number of pixels in vertical and horizontal directions to find total number of pixels =
(1024 × 1080) = 1 105 920 pixels
ii. Now multiply number of pixels by colour depth then divide by 8 to give the number of bytes
= 1 105 920 × 32 = 35 389 440/8 bytes = 4 423 680 bytes
iii. 64 GiB = 64 × 1024 × 1024 × 1024 = 68 719 476 736 bytes
iv. Finally divide the memory stick size by the files size = 68 719 476 736/4 423 680 = 15 534
photos.
12
Example 2
A camera detector has an array of 2048 by 2048 pixels and uses a colour depth of 16. Find the size of an
image taken by this camera in MiB.
i. Multiply number of pixels in vertical and horizontal directions to find total number of pixels = (2 048 ×
2 048) = 4 194 304 pixels
ii. Now multiply number of pixels by colour depth = 4 194 304 × 16 = 67 108 864 bits
iii. Now divide number of bits by 8 to find the number of bytes in the file = (67 108 864)/8 = 8 388 608
bytes
iv. Now divide by 1024 × 1024 to convert to MiB = (8 388 608)/(1 048 576) = 8 MiB.
Example 3
An audio CD has a sample rate of 44 100 and a sample resolution of 16 bits. The music being sampled uses
two channels to allow for stereo recording. Calculate the file size for a 60-minute recording.
i. Size of file = sample rate (in Hz) × sample resolution (in bits) × length of sample (in seconds)
ii. Size of sample = (44 100 × 16 × (60 × 60)) = 2 540 160 000 bits
iii. Multiply by 2 since there are two channels being used = 5 080 320 000 bits
iv. Divide by 8 to find number of bytes = (5 080 320 000)/8 = 635 040 000
v. Divide by 1024 × 1024 to convert to MiB = 635 040 000 / 1 048 576 = 605 MiB.
Data compression
Compression means the reduction of the size of a file by removing repeated or redundant pieces of
data; this can be lossy or lossless
• With this technique, the file compression algorithm eliminates unnecessary data from the
file.
• It results in some loss of detail when compared to the original file.
• This means the original file cannot be reconstructed once it has been compressed.
• The algorithm has to decide which parts of the file need to be retained and which parts can
be discarded.
• Lossy files are smaller than lossless files.
• Common lossy file compression algorithms are MPEG-3 (MP3), MPEG-4 (MP4) and JPEG.
13
When applying a lossy file compression algorithm to:
MP3 files are used for playing music on computers or mobile phones. This compression technology
will reduce the size of a normal music file by about 90%.
• The algorithm removes sounds that the human ear can’t hear properly. For example:
removal of sounds outside the human ear range. This is called perceptual music shaping
(PMS).
• With this technique, all the data from the original uncompressed file can be reconstructed.
• None of the original detail from the file is lost.
Run-length encoding (RLE) can be used for lossless compression of a number of different file
formats:
• it reduces the size of a string of adjacent, identical data (e.g. repeated colours in an image)
• a repeating string is encoded into two values:
o the first value represents the number of identical data items (e.g. characters) in the
run
o the second value represents the code of the data item (such as ASCII code if it is a
keyboard character)
The letter ‘F’ in a grid where each square requires 1 byte of storage. A white square has a value 1 and a black
square a value of 0:
The 8 × 8 grid would need 64 bytes; the compressed RLE format has 30 values, and therefore needs
only 30 bytes to store the image.
14