0% found this document useful (0 votes)
6 views

Data Representation Notes-2

The document covers data representation in computers, focusing on number systems such as binary, decimal, and hexadecimal, along with conversion methods between them. It explains binary addition, overflow errors, and introduces two's complement for representing negative numbers. Additionally, it discusses how text, images, and sound are represented in binary, including the implications of resolution and color depth on file size.

Uploaded by

567 899
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Data Representation Notes-2

The document covers data representation in computers, focusing on number systems such as binary, decimal, and hexadecimal, along with conversion methods between them. It explains binary addition, overflow errors, and introduces two's complement for representing negative numbers. Additionally, it discusses how text, images, and sound are represented in binary, including the implications of resolution and color depth on file size.

Uploaded by

567 899
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Chapter1: Data Representation

Number System
Since computers contain millions and millions of tiny ‘switches’, which must be in the ON or OFF position, they
can be represented by the binary system. A switch in the ON position is represented by 1; a switch in the OFF
position is represented by 0.

Binary, denary and hexadecimal systems


The binary number system is a base 2 number system. Only the two ‘values’ 0 and 1 can be used in this system to
represent all values. Ex; 1101101

Decimal number is a base 10 number system. Values from 0 to 9 are used to represent all values. Ex; 65, 562

Hexadecimal number is a base 16 number system. Values form 0 to 15 are used, from 10 to 15 letters A,B,C,D,E,F
are used to represent values. Ex; 2A, FD8, E04

1. Converting Binary to Denary


Convert the binary number, 11101110, into a denary number

The equivalent denary number is 128 + 64 + 32 + 8 + 4 + 2 = 238

2. Converting from denary to binary


Consider the conversion of the denary number, 142, into binary:

Method 1

The denary number 142 is made up of 128 + 8 + 4 + 2

1|Page
The hexadecimal system
Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent
each hexadecimal (hex) digit. A in hex = 10 in denary, B = 11, C = 12, D = 13, E = 14 and F = 15.

A typical example of hex is 2 1 F 3 A. Since 16 = 24 this means that FOUR binary digits are equivalent to each
hexadecimal digit. The following table summarises the link between binary, hexadecimal and denary:

Table 1.1

3. Converting from binary to hexadecimal

2|Page
4. Converting from Hexadecimal to binary
Converting from hexadecimal to binary is also very straightforward. Using the data in Table 1.1, simply take each
hexadecimal digit and write down the 4-bit code which corresponds to the digit.

5. Converting from hexadecimal to denary


Convert the hexadecimal value 2A6 into Denary value

Convert the hexadecimal value into binary then binary into decimal

2A6 = 0010 1010 0110

2048 1024 512 256 128 64 32 16 8 4 2 1


0 0 1 0 1 0 1 0 0 1 1 0
Ans: Addition of all 1 digits 512+128+32+4+2 = 678

6. Converting from denary to hexadecimal


Convert denary value 459 into Hexadecimal

Convert into binary

512 256 128 64 32 16 8 4 2 1


0 1 1 1 0 0 1 0 1 1

Now convert the binary into hexadecimal by splitting into 4bits

0 1 1 1 0 0 1 0 1 1
1 12 11

1 (C) (B)

Ans: 1CB

3|Page
Four uses/Applications of the hexadecimal system:

 used in Showing error codes on computer


 used in representing MAC addresses
 used in representing IPv6 addresses
 used in HTML colour codes

Why hexadecimal numbers are used in computer system

 It can fit into smaller display screen


 Smaller amount of memory needed to store
 Easier to read/understand
 Easier to identify errors

Addition of binary numbers


This section will look at the addition of two 8-bit positive binary numbers. Note the following key facts when
carrying out addition of two binary digits

4|Page
Activity
a) 0 0 0 1 1 1 0 1 + 0 1 1 0 0 1 1 0 b) 144 + 63

(b) Understand the concept of overflow and why it occurs in binary addition
• An overflow error will occur if the value is greater than 255 in an 8-bit register

This addition has generated a 9th bit. The 8 bits of the answer are 01001100 – this gives the denary value [64 + 8 +
4] of 76 which is incorrect because the denary value of the addition is 110 + 222 = 332

The maximum denary value of an 8-bit binary number is 255. The generation of a 9th bit is clear indication that the
sum has exceeded this value. This is known as an overflow error.

Activity:

Convert the following pairs of denary numbers to 8-bit binary numbers and then add the binary numbers.
Comment on your answers in each case:

a) 11011010 + 01010111 b) 168 + 99


5|Page
Logical Binary Shift

6|Page
7|Page
Two’s complement (binary numbers)
Up until now, we have assumed all binary numbers are positive integers. To allow the possibility of representing
negative integers we make use of two’s complement. Only one minor change to the binary headings needs to be
introduced here:

A 1-value in the left-most bit indicates a negative number and a 0-value in the leftmost bit indicates a positive
number (for example, 00110011 represents 51 and 11001111 represents −49).

-128 64 32 16 8 4 2 1
0 0 1 1 0 0 1 1
denary number is 51

8|Page
-128 64 32 16 8 4 2 1
1 1 0 0 1 1 1 1
Denary number is -49

-128 + 64 + 8 + 4 + 2 + 1 = -49

Writing postive binary numbers in two’s complement format

Activity

Convert the following positive denary numbers into 8-bit binary numbers in the two’s complement format:

a) 39 b) 125

Convert the following binary numbers (written in two’s complement format) into positive denary numbers:

a)

-128 64 32 16 8 4 2 1
0 1 0 1 0 1 0 1

b)

-128 64 32 16 8 4 2 1
0 1 1 1 1 1 0 1

9|Page
Writing Negative denary number in two’s complement format
a) Convert the negative denary numbers -56 in two’s complement format in 8-bit register

As it is a negative number, we need a 1-value in the -128 column

-56 is the same as -128 + 72 //128 - 56 = 72

72 is made up of 64 + 8

-128 64 32 16 8 4 2 1
1 1 0 0 1 0 0 0

b) Convert -79 into an 8 – bit binary number using two’s complement format.

As it is a negative number, we need a 1-value in the -128 column

-79 is the same as -128 + 49 //128 – 79 = 49

49 is made up of 32 + 16 + 1

-128 64 32 16 8 4 2 1
1 0 1 1 0 0 0 1

Activity:

1. Convert the following negative denary numbers into binary numbers using the two’s complement format:

a) - 18 b) - 92

10 | P a g e
Activity:

1. Convert the following negative binary numbers [written in two’s complement format] into negative denary
numbers:

-128 64 32 16 8 4 2 1
1 1 0 0 1 1 0 1

-128 64 32 16 8 4 2 1
1 0 1 0 1 1 0 0

Text, sound and images


Representation of Text file in binary
 Text is a collection of characters that can be represented in binary, which is the language that computers
use to process information
 To represent text in binary, a computer uses a character set, which is a collection of characters and the
corresponding binary codes that represent them
 One of the most commonly used character sets is the American Standard Code for Information
Interchange(ASCII), which assigns a unique 7-bit binary code to each character, including uppercase and
lowercase letters, digits, punctuation marks, and control characters
 E.g. The ASCII code for the uppercase letter 'A' is 01000001, while the code for the character'?' is
00111111
 ASCII has limitations in terms of the number of characters it can represent, and it does not support
characters from languages other than English
11 | P a g e
 To address these limitations, Unicode was developed as a character encoding standard that allows for a
greater range of characters and symbols than ASCII, including different languages and emojis
 Unicode uses a variable-length encoding scheme that assigns a unique code to each character, which can
be represented binary form using multiple bytes
 E.g. The Unicode code for the heart symbol is U+2665, which can be represented in binary form as
11100110 10011000 10100101
 AS Unicode required more bits per character than ASCII, it can result in larges file sizes and slower
processing times when working with text-based data

Representation of Images in binary


 Pixel is very small dot of colour that is displayed with many others to create an image.
 Resolution is the dimensions of an image. It refers to the numbers of pixels that make up an image. For
example, an image could contain 4096 x 3072 pixels (12 582 912 pixels in total)
 Colour depth is the number of bits that are used to create each colour in an image
 A black and white image only required 1 bit per pixel – this means that each pixel can be on two colours,
either 1 or 0
 If each pixel is represented by 2 bits, then each pixel can be of one of four colours (22 = 4)
 If each pixel is represented by 3 bits then each pixel can be on of eight colours (23 = 8)
 An 8 bit colour depth means that each pixel can be one of 256 colours (28 = 256)
 Modern computers have a 24 bit colour depth, which mean over 16 million different colours can be used.

Increasing colour depth also increases the size of the file when storing an image.

The resolution can be varied on many cameras before taking. In the given picture below, Image ‘A’ has the highest
resolution and ‘E’ has the lowest resolution. This is because there are fewer pixels in ‘E’.

12 | P a g e
Drawback of high resolution:

 Increase in pixels
 Increase in file size
 Takes more time to download from internet
 Takes more time to transfer from device to device

Exercise question1:

One of the images has a resolution of 1000 x 1000 and a colour depth of 16 bits. Calculate the file size
of the image. Give your answer in bytes.

Show your working

1000 x 1000 = 1000000 pixels

1000000 x 16 = 16 000 000 bits

16 000 000 / 8 = 2 000 000 bytes

File Size: 2 000 000 bytes

Exercise question2:

George is a wedding photographer. She wants to store 10 photographs on a USB flash memory drive for
a customer. Each photograph is 100 pixels wide and 50 pixels high. The photographs are 8-bit colour
photographs.

a) Calculate the total file size, in kilobytes(kB), of all the photographs. For this calculation, you may use the unit
of measurement of 1024 or 1000.

Show all your working

100 x 50 = 5000 pixels

5000 x 8 = 40 000 bits

40 000 / 8 = 5 000 bytes

5000 / 1000 = 5 KB
13 | P a g e
A File Size 5 KB

File size for 10 photographs,

10 x 5 = 50 KB

Exercise question3:

Jessica wants to store a large number of small thumbnail images on a USB flash memory drive. Each thumbnail
image is 16-bit colour and is 100 pixels wide and 100 pixels high.

She has 5MB of storage space available on her USB flash memory drive.

Calculate how many images she can store in the 5MB of storage space. Show all your working

100 x 100 = 10000 pixels

10000 x 16 = 16 0000 bits

16 0000 / 8 = 2 0000 bytes

2 0000 / 1024 = 19 KiB

Convert 5MB pen drive into KiB

5 x 1024 = 5120 KiB

Number of images,

5120 / 19 = 269 image

Exercise Question4:

1024 x 1080 = 1,105,920 pixels

1,105,920 x 32 = 35,389,440 bits

35,389,440 / 8 = 4,423,680 bytes

4,423,680 / 1024 = 4,320 KiB

4,320 / 1024 = 4.2 MiB

Convert memory stick of 64GiB into MiB

64 x 1024 = 65,536 MiB

Number of Photographs

65,536 / 4.2 = 15,603

14 | P a g e
Representation of sound in binary
Sound is made up of sound waves. When sound is recorded, this done at set time intervals. This process is known
as sound sampling.

Sound sampling is a little piece of sound that is recorded at regular time intervals.

Sample rate is the number of samples recorded each second

Sample resolution is the number of bits that are used to record each sound sample

The above picture is an example of sound wave

If you recorded the sound at each time sample, you would have the following set of values:

Time sample 1 2 3 4 5 6 7 8 9 10 11 12
Sound value 9 13 9 3.5 4 9 1.5 9 8 5 8 5.5
Each sound wave is converted to binary to be processed by the computer. Each sound value is then used to
playback the sound, when the recording is played. If the recorded sound wave is played it would now look like the
figure given below

You will notice that the two sound waves look different. This is because the number of sample taken is too far
apart, so vital data is between time samples has been lost. This will result in a lack of accuracy in the sound that is
recorded. Therefore, more sound samples need to be taken each second to improve the accuracy of the recorded
sound. The number of samples taken in a second is called the sample rate. Sample rates are measured in hertz. 1
hertz is equal to 1 sample per second. A common sample rate is 44.1khz(kilohertz), this would require 44100
sample to be taken each second. That is a lot of data! If the sample rate is increased, the amount of data required
for the recording is increased. This increases the size of the file that stores the sound.

Further data is required to represent sound, and this is the sample resolution. Sample resolution is the number of
bits that are used to record each sound sample

15 | P a g e
A common sample resolution is 16 bit. The higher the sample resolution the greater the variations in amplitude
that can be stored for each sample. This means the sound can be recorded more accurately.

How sample resolution creates more accurate recording:

 More bits allocated to each amplitude.


 Amplitudes can be more precise.
 A wider range of amplitudes can be recorded.

This will also increase the amount of data and file size to be stored for each sample.

Exercise 1:
An audio CD has a sample rate of 44100 Hz and a sample resolution of 16 bits. Calculate the file size for 12
seconds recording

Size of file =

Size of sample = 44100 x 16 x 12 = 8467200 bits

8467200 / 8 = 1058400 bytes

1058400 / 1024 = 1033 Kib

1033 / 1024 = 1 MiB

Exercise 2:

Audio is being sampled at the rate of 44.1kHz using 8 bits. Two channels are being used for stereo sound.
Calculate:

a) The size of a one second sample, in bits

b) The size of a 30 second audio recording in MiB

Size of file for one second = 44100 x 8 = 352800 bits

352800 x 30 = 10584000 bits for 30 seconds

10584000 / 8 = 1323000 bytes

1323000 / 1024 = 1291 Kib

1291 / 1024 = 1.2 Mib

File size for two channels,

2 X 1.2 = 2.4 Mib

16 | P a g e
Exercise 3:

The typical song stored on a music CD is 1 minute. Assuming each song is sampled at 44.1kHz(44100 samples per
second) and 16 bits are used per sample. Each song utilises two channels.

Calculate how many typical songs could be stored on a 740 MiB CD

File Compression
Compression is a method that uses an algorithm to reduce the size of a file

Benefits of compressing a file,

 Not as much storage space is needed to store


 less time to transmit the file from one device to another
 Quicker to upload and download the file
 Not as much bandwidth is needed to transmit over internet

There are two types of compression 1) Lossy 2) Lossless

Lossy Compression

A compression method that reduces the size of a file by permanently removing data

Lossless Compression

A compression method that reduces the size of a file by temporarily altering the data and the data can be
retrieved back

17 | P a g e
How Image file is compressed
● Applied lossy compression algorithm

● Removes redundant data in the file

● Removes colours human eyes can’t distinguish, thus reducing the colour depth

● Reduce the file size by reducing the resolution, pixels

How sound file is compressed


● Repeated or unnecessary sound is removed

● Uses perceptual music shaping, means removes sounds human ears can’t hear very well

● If two sounds played at same time, softer sound is removed

● Reduces file size by reducing sample rate and sample resolution

● Using lossy compression

How Text file is compressed


● Repeated words can be indexed

● Repeated word sections (e.g, “OU”, “THE”) can be replaced by a numerical value

● Index and numerical values are saved in a table of dictionary to recover original file later

● Reference to zip files

● Convert to PDF

● RLE(Run Length Encoding) can be used for lossless compression. It reduces the size of a string of adjacent,
identical data

● Using Lossless compression algorithm

18 | P a g e

You might also like