CH 01
CH 01
CH 01
Chapter 01
Data Representation
Created by:
Mr. Mahmoud Moussa
01098569912
www.mahmoudmoussa.com
Outline
How and why computers use binary to represent all forms of data?
Convert between
Positive denary and positive binary
3
Outline
How and why a computer represents text and the use of character sets, including
American standard code for information interchange (ASCII) and Unicode?
How and why a computer represents sound, including the effects of the sample
rate and sample resolution?
How and why a computer represents an image, including the effects of the
resolution and colour depth?
How data storage is measured?
Calculate the file size of an image file and a sound file, using information given
The purpose of and need for data compression
How files are compressed using lossy and lossless compression methods?
Binary System
Why we use binary to represent data in computers?
0 1 1 0 1 0 1 1
0 + 64 + 32 + 0 + 8 + 2 + 1 = 107
Weight: 26 25 24 23 22 21 20
Binary number: 1 1 0 1 1 0 1
The process of converting the binary number 1101101 into a denary number
Example 1
Q: If the data transfer rate using the internet is 32 megabits per second, how long
it will take to download a 40 MB file?
40MB = 320megabits
320megabits / 32megabits per second
It will take 10 seconds to download a 40MB file.
Example 2
Q: Each image taken requires 1MB of storage. If the camera captures an image
every 30 seconds over a 10 hour period, how much storage is required? Give your
answer in gigabytes and show all your working.
Binary VS Denary
The differences between the binary number system and the denary number system
When computers (or microprocessors) are used to control devices (such as robots)
Registers and sensors are used as part of the control system.
What is meant by the term register?
It is an input device
It measures/takes physical readings of the surrounding environment properties
Such as Temperature sensor, sound sensor, and proximity sensor
17
Applications of Binary System
0 1 1 0 1 0 1 0
18
is represented by:
(clock display)
(a) What time is shown on the clock display if the 4-digit binary codes are:
(b) What would be stored in the 4-digit binary codes if the clock display time was:
0 0 0 1
0 1 1 1
0 0 1 0
(clock display)
1 0 0 1
(clock display)
Applications of Binary System
3 Elevators
A large hotel uses eight lifts (elevators) to carry passengers between its sixty floors. A
computer is used to control and monitor the lifts. Each lift has three registers to represent
its state. 1
Register 1 UP/DOWN 1 = lift going up and 0 = lift going down
4 2 1
Register 2 Lift ID number 0 to 7
32 16 8 4 2 1
Register 3 Floor number 0 to 60
Thus:
1 4 2 1 32 16 8 4 2 1
1 1 0 0 0 1 1 0 1 1
32 16 8 4 2 1
Register 3 Floor number 0 to 60
-----------------------------------------------------------------------------------------------------
(a) If the three registers contain the following data:
1 4 2 1 32 16 8 4 2 1
0 1 1 1 1 1 1 0 0 0
32 16 8 4 2 1
Register 3 Floor number 0 to 60
-----------------------------------------------------------------------------------------------------
(b) How would the following information be shown in the three registers:
lift 6 presently on the 45th floor and going down
1 4 2 1 32 16 8 4 2 1
0 1 1 0 1 0 1 1 0 1
22
D B
D
Example Use of Binary
Uses for a binary number stored in a register
Data
ASCII value or Unicode value
Number
24
9 F 5
-----------------------------------------------------------------------------------------------------
Example 2: Represent binary 10000111111101 in hex.
Solution:
- First the number is grouped into sets of 4 bits.
- The left group contains only 2 bits, so add in 2 0s.
- Each group of 4 bits is replaced with its hex equivalent.
2 1 F D
29
Use of Hexadecimal System
Memory Dumps
Use of Notation for Colour in HyperText
Hexadecimal Mark-up Language (HTML)
System
Media Access Control (MAC) Address
Web Addresses
Assembly Code and Machine Code
Memory location
Use of Hexadecimal System
2 Notation for Colour in HyperText Mark-up Language (HTML)
Describe how other colours, such as a darker shade of blue, are created.
Example:
00 – 1C – B3 – 4F – 25 - EE
Unicode
ASCII TABLE
Example
When a key is pressed on the keyboard, the computer stores the ASCII representation of
the character typed into main memory. The ASCII representation for A is 65 (denary), for B
is 66 (denary), etc. There are two letters stored in the following memory locations:
Location 1 0 1 0 0 0 0 0 1
Location 2 0 1 0 0 0 0 1 1
www.hodder.co.uk
w w w .
%77 %77 %77 %2E
h o d d e r .
%68 %6F %64 %64 %65 %72 %2E
c o . u k
%63 %6F %2E %75 %6B
Use of Hexadecimal System
5 Assembly Code and Machine Code
One of the most common errors you can come across while browsing the
Internet is a #404 or Page Not Found error.
This error often occurs when you follow a broken link or if you type in a website
address that doesn't exist.
A #404 page is a page that explains that a 404 error has occurred.
42
43
Addition of Binary Numbers
Example 1 Add 00100111 + 01001010
111 Carry Values
00100111
+
01001010
44
1 1 11 1 1 1 Carry Values
01101110
+
11011110
9th bit
1 01001100 Sum Values
This addition has generated a 9th bit.
The 8 bits of the answer are 0 1 0 0 1 1 0 0 – this gives the denary value 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 (28 -1)
The generation of a 9th bit is a clear indication that the sum has exceeded this value.
This is known as an overflow error
45
Addition of Binary Numbers
Why overflow error occur in binary addition?
Note
The larger the number of bits which can be used to represent a number
then the larger the number that can be stored.
Example
A 16-bit register would allow a maximum denary value of 65,535
(216 – 1) to be stored
46
The denary number 21 is 00010101 in binary. If we put this into an 8-bit register:
128 64 32 16 8 4 2 1
0 0 0 1 0 1 0 1
If we now shift the bits in this register one place to the left, we obtain:
The denary number 21 is 00010101 in binary. If we put this into an 8-bit register:
128 64 32 16 8 4 2 1
0 0 0 1 0 1 0 1
If we now shift the bits in this register two places to the left, we obtain:
This error is because we have exceeded the maximum number of left shifts
possible using this register
128 64 32 16 8 4 2 1
0 1 1 1 0 0 0 0
112
The original number is shifted three places to the right. Show the new binary number
00001110
128 64 32 16 8 4 2 1
0 1 1 1 0 0 0 0
Describe the problems that could be caused if the original binary number is shifted
five places to the
Run out of places to the right of register
Right-most 1 would be lost
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.
For example
00110011 Positive = 51 in denary
53
Two’s Complement (Binary Numbers)
Example 1
Using two’s complement, show how 114 in base 10 could be stored in an 8-bit
register:
0 1 1 1 0 0 1 0
114/2 57 0
57/2 28 1
28/2 14 0
14/2 7 0
7/2 3 1
3/2 1 1
1/2 0 1
Using two’s complement, show how -93 in base 10 could be stored in an 8-bit
register:
1 0 1 0 0 0 1 1
Two’s Complement (Binary Numbers)
Example 3
Using two’s complement, show how -77 could be stored in an 8-bit register
1 0 1 1 0 0 1 1
Using two’s complement, show how to convert the binary value 1001 0011 to denary
-128 64 32 16 8 4 2 1
1 0 0 1 0 0 1 1
-128 + 16 + 2 + 1 = - 109
57
Representation of sound
Difference between analogue and digital data
Analogue data
Continuous data
Non-discrete data
Digital data
Representation of Sound
Soundwaves are vibrations in the air
The human ear senses these vibrations and interprets them as sound
59
Representation of Sound
Sound waves vary continuously
This means that sound is analogue.
Computers cannot work with analogue data.
Sampling
Representation of Sound
Sampling Rate
The number of samples taken per unit time
Sampling Resolution
The higher the sampling resolution, the smaller the quantization error
61
Usually 8 bit, 16 bit, 24 bit or 32 bit
Representation of Sound
The benefits and drawbacks of using a larger sampling resolution when recording
sound
Benefits
Larger dynamic range
Drawbacks
Produces larger file size
Representation of Sound
How sampling is used to record the sound clips?
Increasing the sampling rate will improve the accuracy of the recording
63
Representation of Bitmap Images
Bitmap Image
Made up of pixels
Made up of a two-dimensional matrix of pixels
Each pixel has one colour
Colour of each pixel stored as a binary number
Colour depth
File Header
Note
The file size and quality of the image increases as the resolution and colour depth increase
65
Calculation of File Size
The file size of an image is calculated as:
Image Resolution (in pixels) × Colour Depth (in bits)
66
The image is scanned with an image resolution of 1024 × 512 pixels, and a colour
depth of 8 bits per pixel. Calculate an estimate for the file size, giving your answer in
mebibytes. Show your working.
67
Calculation of File Size
Example 2
68
1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 0 1 1
10 x 10 x 2 = 200bits
200 / 8 = 25Bytes
OR
Each row contains 20bit which is equal 2.5B
69
Calculation of File Size
Example 3
A camera detector has an array of 2048 by 2048 pixels and uses a colour depth of
16 bits per pixel. Find the size of an image taken by this camera in MiB.
2 x 2048 x 2 / 1024
2 x 2x 2 = 8MiB
70
Sample Rate (in Hz) × Sample Resolution (in bits) × Length of Sample (in seconds)
44100 × 8 × 10
44100 × 1 × 10
441000 B
File Formats
MPEG-4 (MP4)
This format allows the storage of multimedia files rather than just sound
Music, videos, photos and animation can all be stored in the MP4 format
MP3 and MP4 files use what is known as a LOSSY FORMAT. WHY??
Since part of the original file is lost following the compression algorithm
File Formats
MP3 file Features
MP3
Digital recording of sound
Produced by recording software and a microphone
Used when distributing sound files
Compressed file format
File Formats
Joint Photographic Experts Group (jpeg) files
TIFF (Tagged Image File Format ) and BMP (bitmap) are the highest image
quality because, unlike jpeg, they are not in a compressed format
Low resolution
Even the sharp image in picture Y would become fuzzy if enlarged. Why would this happen?
As picture is enlarged covers larger area
File Formats
Text and number file formats
Examples of text file formats
File Compression
Lossless file compression
File size is reduced
No information is lost
The process can be reversed to re-create the original file
Used to compress text files
.bmp (bitmap) and .png (Portable Network Graphics) use lossless encoding
Lossy file compression
With this technique, the file compression algorithm eliminates unnecessary
bits of data as seen in MP3 and jpeg formats
This is why it is chosen for files where removing certain bits doesn’t detract
from the quality
File Compression
Benefits of compressing a large file to send it over the internet
Smaller file to transmit
File Compression
How a text file is compressed using lossless compression.
Repeated patterns of notes are identified and are grouped, with an index
File Compression
Example of using lossless compression in a text file
Consider the phrase ‘THIS SECTION SHOWS YOU HOW THIS WOULD
WORK’ which consists of 35 memory units (ignoring spaces)
Repeated words, such as ‘THIS’ could be put into Word Value
a data dictionary and be replaced by ‘1’. THIS 1
Repeated word sections, such as ‘HOW’ and ‘OU’ HOW 2
could be replaced by the numbers ‘2’ and ‘3’. OU 3
Ignoring spaces, this compressed form now uses only 23 memory units.
File Compression
How to reduce the file size of a video as much as possible.
Best compression would be lossy
Use compression algorithm
This would remove all the unnecessary data from the file, removes the pixels
the human eye may not see and sound that the human ear may not hear
One value represents the number of identical characters in the run (the run count)
The other value is the code of the character or colour code of pixel in the run (the
run value)
The run value and run count combination may be preceded by a control character
Note
RLE is only effective where there is a long run of repeated bits.
84
File Compression
RLE on Text Data Example 1
a a a a a b b b b c c d d d d d
5 97 4 98 2 99 5 100
Note
Assuming each number in the second row requires 1 byte of memory, the
RLE code will need 8 bytes. This is half the original file size
85
File Compression
RLE on Text Data Example 2
86
File Compression
String aaaaaaaa bbbbbbbbbb c d c d c d eeeeeeee
Code 8 97 10 98 1 99 1 100 1 99 1 100 1 99 1 100 8 101
The coded version contains 18 values and would require 18 bytes of storage
Introducing a flag (255 in this case) produces
255 08 97 || 255 10 98 || 99 100 99 100 99 100 || 255 08 101
This has 15 values and would, therefore, require 15 bytes of storage.
Note
This means that 255 is the flag and the other two numbers
255 08 97 indicate that there are eight items with ASCII code 97
Using the flag reduced the file size from 18 bytes to 15bytes
87
File Compression
RLE on Image Data Example 2
Colour Colour
The following diagrams show: Symbol (denary)
The denary colour code that represents each colour B 153
The first three rows of a bitmap image
W 255
Show how RLE will compress the first three rows of this image.
Row 1: 10 153 3 255 3 153 Row 3: 7 153 9 255
Row 2: 9 153 6 255 1 153 88