0% found this document useful (0 votes)
17 views102 pages

Ch1 DataRepresentation

IGCSE computer science revision

Uploaded by

blengidey38
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views102 pages

Ch1 DataRepresentation

IGCSE computer science revision

Uploaded by

blengidey38
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 102

Data Representation

Chapter 1

This chapter considers the three main Number systems and how they are used to measure
computers memory and storage
Ch1: Data Representation

1.1 Number Systems

1.2 Text, Sound and Images

1.3 Data Storage and Compression


1.1 Number Systems
We will consider the 3 key number systems used
in computer science : Binary, Denary and
Hexadecimal.
1.1.1
Binary represents data
Understand how and why computers use binary to represent all forms of data
1.1.1 Binary represents data

Any format of data needs to be converted to a binary


format so that it can be processed by the computer
Binary System

0 1
1.1.2 Binary, Denary and Hexadecimal
Systems

A base 10 System A base 2 System A base 16 System


0-9 0-1 0-15

Denary Binary Hexadecimal


1.1.2 Binary, Denary and Hexadecimal Systems
Denary Number?

104 103 102 101 100


10000 1000 100 10 1
5 3 2 1 7

Binary Number?

27 26 25 24 23 22 21 20
Let’s convert some
128 64 32 16 8 4 2 1 numbers
1 0 0 1 1 0 1 0
Converting Binary Example
numbers to Denary
11101110
2+4+8+32+64 27 26 25 24 23 22 21 20
+128= 238 128 64 32 16 8 4 2 1
1 1 1 0 1 1 1 0

1x128 1x64 1x32 1x16 1x8 1x4 1x2 1x0


Classwork- Page#4(book)

Converting Binary
numbers to Denary a. 00110011
b. 01 111 1 11
c. 10011001
d. 01110100
Converting Denary
numbers to Binary Example- Method 1

142-128=14 142
14-8=6 27 26 25 24 23 22 21 20
6-4=2 128 64 32 16 8 4 2 1

2-2=0 1 0 0 0 1 1 1 0
http://games.penjee.com/binar
y-numbers-game/
Play a game?
Let’s Practice a little

Convert the following binary numbers into


denary:
Convert the following denary numbers into
00110011 binary (using both methods):
01111111 41
00001111 67
10001111 86
10110011 100
0011111100001101 200
255
33000

http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html
1.1.2 Binary, Denary and Hexadecimal Systems
Hexadecimal System

0-9 164 163 162 161 160


10 A
11 B 65536 4096 256 16 1
12 C 2 1 F 3 A
13 D
14 E
4
15 F
16=2
Let’s link Binary, Denary and Hexadecimal systems
Binary Hexadecimal Denary
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 A 10
1011 B 11
1100 C 12
1101 D 13
1110 E 14
1111 F 15
Hexadecimal System
Every 4 binary digits are
represented by one
hexadecimal

110111100001
Split it into groups of 4 bits

1101 1110 0001

B E 1
Hexadecimal
16 conversions
From hexadecimal to denary and from denary to hexadecimal
1.1.3 Use of Hexadecimal System
Binary
1101001010101111
Hexadecimal D2AF
The hex number
is far easier for humans to
remember, copy and work
with
1.1.3 Uses of hexadecimal system
404 NOT
FOUND

Error codes MAC addresses


often shown as hexadecimal values. These Media Access Control (MAC) address refers to a
numbers refer to the memory location of number which uniquely identifies a device on a
the error and are usually automatically network. The MAC address refers to the network
generated by the computer interface card (NIC) which is part of the device

IPv6
HTML color codes
a 128-bit number broken down into 16-bit HTML is often used to represent colours of text on the
chunks computer screen
Error codes

1.1.3 Uses of hexadecimal system

p s
u m
y d
o r
e m
M
MAC addresses

1.1.3 Uses of hexadecimal system


A MAC address is usually made up of 48 bits which are shown as 6 groups of two
hexadecimal digits (although 64-bit addresses also exist)

NN-NN-NN-DD-DD-DD or NN:NN:NN:DD:DD:DD

Manufacturer of the Serial number of the


device device
IPv6

1.1.3 Uses of hexadecimal system


Each device connected to a network is given an address known as the Internet
Protocol (IP) address

IPv4 address IPv6 address


a 32-bit number written in a 128-bit number broken down into 16-bit chunks,
denary or hexadecimal represented by a hexadecimal number.
form Improved
e.g. a8fb:7a88:fff0:0fff:3d21:2085:66fb:f0fa
e.g. 109.108.158.1 (or
77.76.9e.01 in hex)

IPv6 uses a colon (:) rather than a decimal point (.) as used in IPv4
HTML Color Codes

1.1.3 Uses of hexadecimal system


HTML is often used to represent colours of text on the computer screen. All colours can be made up of
different combinations of the three primary colours (red, green and blue)

# R G B
# FF 00 00 red
# 00 FF 00 green
# 00 00 FF blue
1.1.4
Addition of binary numbers
Addition oftwo 8-bit positive binary numbers
Simalarity to denary addition

Denary Binary
11 1010
137 11100
194
10110
331
Perform the above additions
Overflow

The generation of a
01101110 number or other data
Overflow
Error 11011110 item that is too large for
the assigned location or
101001100 memory space
1.1.5
Logical binary shifts
Computerscan carry logical shifts which means moving the binary numbers to the
left or right
Logical Shifts
Multiplication (shift to the Division (shift to the right)
left)
Equivalent to dividing
Equivalent to the binary number by
multiplying the binary 2
number by 2
Multiplication

Logical Shifts
128 64 32 16 8 4 2 1

1 0 1 0

1 0 1 0 0

Multiplying by 2 shifts 1 place to the left


Multiplying by 4 shifts 2 places to the left
Multiplying by 8 shifts 3 places to the left
Division

Logical Shifts
128 64 32 16 8 4 2 1

1 0 1 1 0 0

1 0 1 1 0

Dividing by 2 shifts 1 place to the right


Dividing by 4 shifts 2 places to the right
Dividing by 8 shifts 3 places to the right
Most
Significant BIT
128 64 32 16 8 4 2 1

0 0 0 1 0 1 0 1
Multiply by 2

0 0 1 0 1 0 1 0
Multiply by 4

0 1 0 1 0 1 0 0
Multiply by 8

1 0 1 0 1 0 0 0
Multiply by 16

0 1 0 1 0 0 0 0
Logical Shifts
1.1.6
Two’s Complement
So farwe have looked at how to represent positive numbers in binary. For negative
numbers a system called Two’s Complement is used.
1.1.6 Two’s complement
What is the binary number for the denary number 15?

0000 1111
How do you think -15 is represented?
1.1.6 Two’s complement

15 0000 1111
-15 1111 0001
1.1.6 Two’s complement
The two’s complement is calculated as follows:
128 64 32 16 8 4 2 1 Calculating -15

15 0 0 0 0 1 1 1 1 First convert 15 to binary

1 1 1 1 0 0 0 0 Then invert all the bits

-15 1 1 1 1 0 0 0 1 Finally add 1 to the number

8-bits allow numbers between -128 and 127 to be represented


1.1.6 Two’s complement

What does the following two’s complement negative number


represent?

1011 0001
1.1.6 Two’s complement
’ s e!
et
L ac t i c 1011 0001
p r 128 64 32 16 8 4 2 1

1 0 1 1 0 0 0 1

0 1 0 0 1 1 1 0 Invert the bits

0 1 0 0 1 1 1 1 Add 1

01001111 represents 79, so 10110001 represents -79


1.2
Text, sound and images
1.2.1
Character sets- ASCII code and
Objectives Unicode
Understand the use of binary codes to represent characters
Understand the term ‘character set’
Explain the relationship between the number of bits per character in a character set, and the
number of characters that can be represented using:
• ASCII
• Extended ASCII
• Unicode
ASCII and Unicode
Unit 2 Data representation

Starter
• A computers memory and storage only hold binary 1s and 0s
• How might it be possible to store letters with only binary?
ASCII and Unicode
Unit 2 Data representation

Representing text characters


If a computer understands only 1s and 0s, what happens when the ‘M’ key
is pressed on the keyboard?

0 1 0 0 1 1 0 1
ASCII and Unicode
Unit 2 Data representation

Representing characters
in binary
• Every character on the keyboard is represented by a binary value
• Uppercase letters (capitals) have different values from lowercase characters
• Punctuation symbols have their own character code

• How many characters are there on a standard keyboard?


• How many bits would be required to represent this many combinations?
ASCII and Unicode
Unit 2 Data representation

Characters in binary
• A keyboard needs to contain
• 26 lowercase letters
• 26 uppercase letters
• 10 numbers
• (around) 36 other characters

• There are around 98 unique characters that are available on a keyboard


• 6 bits give 64 different combinations – this isn’t enough
• 7 bits give 128 different combinations which can represent 128 different characters
ASCII and Unicode
Unit 2 Data representation

Character sets
• A character set is a set of letters, symbols and digits that can be represented by
a computer
• There are two major character sets in use today
• ASCII
• Unicode
ASCII and Unicode
Unit 2 Data representation

The ASCII character set


• ASCII (American Standard Code for Information Interchange) has become the
standard code, used worldwide
• It was originally developed in the 1960s for representing the English alphabet
• It encodes 128 characters into 7-bit binary codes

• Characters include numbers 0 to 9, uppercase and lowercase letters A-Z, a-z,


punctuation symbols and the space character
ASCII and Unicode
Unit 2 Data representation

The ASCII character set


• What is the ASCII character for the number 7? Is this the same as the binary value
for 7?
• Why not? What is happening? What does this mean?
ASCII and Unicode
Unit 2 Data representation

ASCII groups and sequences


• Character codes are commonly grouped and run in sequence
• Numeric characters 0 to 9 run consecutively from 48 to 57 on the ASCII table

• A-Z characters are from 65-90 or


01000001 to 01011010
• What range does lowercase characters a-z use?
• If you know Capital A is 65 or 01000001, what is Capital E?
ASCII and Unicode
Unit 2 Data representation

ASCII character set


• ASCII character 32 (010 0000) represents a space
• The ASCII character code for ‘7’ is 55
• 55 (011 0111) is the ASCII character code that represents the character ‘7’
• In programming this is very different to the integer 7 which is represented by 0000 0111 (7)

• Lowercase characters a-z use 97-122


• If A is 65 (0100 0001) then E is 69 (0100 0101)
ASCII and Unicode
Unit 2 Data representation

7- and 8-bit ASCII


• Numerous different codes for representing characters have been created, but ASCII is
commonly used on PCs

• Originally only seven bits were used, but now an eighth bit is used allowing for many
more characters such as ©, ® etc.
• 8-bit ASCII is called Extended ASCII
• How many different characters can be encoded using
7 bits, 8 bits or 16 bits?
ASCII and Unicode
Unit 2 Data representation

Character codes
• A 7-bit character code (like ASCII) has
128 different characters that can be encoded
• An 8-bit character code (like extended ASCII) has
256 different characters that can be encoded
• A 16-bit character code has 65 536 different characters that can be encoded
ASCII and Unicode
Unit 2 Data representation

Using different alphabets


• To represent other characters for different languages, a new code allowing for
many more characters is needed
• Unicode was developed to use 16 bits 65 536
possible combinations
• The 32 bit version gives 4 294 967 296 (over 4 billion) possible combinations
ASCII and Unicode
Unit 2 Data representation

Unicode
• In Japanese, konnichiwa is used as a greeting meaning ‘good day’
• In Unicode this is written as three 16-bit characters

• How many bytes does the English ‘good day’ require


in ASCII?
• How many bytes does the Japanese require in Unicode?
ASCII and Unicode
Unit 2 Data representation

Unicode
• ‘good day’ requires 8 bytes to store
• 今日は requires 6 bytes to store
(3 characters × 2 bytes)
• Unicode is also used to
store emoji
• ‘e’ is Japanese for picture
• ‘moji’ is Japanese for
character or alphabet

Smiling face with sunglasses


Unicode: 1F60E
ASCII and Unicode
Unit 2 Data representation

Plenary
• Work in a pair to answer the following questions
• How many bits are in extended ASCII?
• How many characters does this allow for?
• How many bytes are in Unicode?
• If ‘f’ has the ASCII code 102, what is the ASCII code for ‘g’?
• How many bytes are needed to store “Hello everyone.”?
ASCII and Unicode
Unit 2 Data representation

Plenary
• How many bits are in extended ASCII? 8 bits
• How many characters does this allow for? 256
• How many bytes are in Unicode?
16-bit has 2 bytes, 32-bit has 4 bytes
• If ‘f’ has the ASCII code 102, what is the ASCII code for ‘g’? 103
• How many bytes are needed to store “Hello everyone.”?
15 letters (remember space and the full stop)
1.2.2 Representation of Sound
Analogue sound signals are continuous

Digital signals are discrete (not continuous)

1 0 1 0 1 0 1 0 1 0 1 0

Sound is digitised by repeatedly measuring and recording the sound wave


1.2.2 Representation of Sound
Each sound wave
has frequency,
wavelength and
amplitude
1.2.2 Representation of Sound
Analogue to digital convertors
Sounds must be converted into a digital form in order to be stored and processed by a computer
• An Analogue to Digital Convertor (ADC) is used to convert inputs to digital signals.
• A Digital to Analogue Convertor (DAC) is used to convert digital signals to outputs.
1.2.2 Representation of Sound
Sound sampling
A sound sample is a measurement of amplitude of a sound wave at a given time. It’s measured in Hertz.
1.2.2 Representation of Sound
How’s sampling used to record sound clip?
• The amplitude of the sound wave is first determined at set time intervals (the sampling rate).

• This gives and approximate representation of the sound wave.

• Each sample of the sound wave is then encoded as series of binary digits.
1.2.2 Representation of Sound
Sample Resolution (bit depth)
Is the number of bits per sample

Higher (4-bit) resolution Lower (3-bit) resolution


1.2.2 Representation of Sound
Sample Rate
Sample rate is usually measured in hertz (Hz)
1 Hz = 1 sample per second
CDs are usually sampled at 44,100 Hz (44.1 kHz)

What is the
sample rate in
hertz of the this
sample?
1.2.2 Representation of Sound
Sample Rate
• The frequency or sample rate per second affects the level of detail in the digital representation
• The greater the frequency, the greater the accuracy, and file size

Higher frequency Lower frequency


1.2.2 Representation of Sound
Calculating sound files sizes

File size (bits) = sample rate × resolution × duration


6 samples per second × 4-bit resolution × 3 seconds = 72

72 bits / 8 = 9 bytes
1.2.2 Representation of Sound
In pairs, take turns to test each other on the
following questions:
• The sample rate is measured in what unit?
• The number of bits available to store each sample is known as what?
• What is the formula for calculating the size of an uncompressed music
file?
• Track1.wav uses a sample rate of 20 kHz, Track2.wav uses a sample
rate of 10 kHz. Which file is the higher quality? Which is the larger file
size?
ANSWERS

1.2.2 Representation of Sound


In pairs, take turns to test each other on the
following questions:
• The sample rate is measured in what unit? Hertz (Hz)
• The number of bits available to store each sample is known as what? Resolution
(bit depth)
• What is the formula for calculating the size of an uncompressed music file?
Sample rate x resolution x duration
• Track1.wav uses a sample rate of 20 kHz, Track2.wav uses a sample rate of 10
kHz. Which file is the higher quality? Which is the larger file size?
Track1 is higher quality and a larger file size
1.2.3
Representation of Bitmap images
Bitmap image file formats:
BMP
JPG
GIF
PNG
TIFF
1.2.3 Representation of Bitmap images
• Bitmap images are made up of PICture ELement or
pixels
• A pixel is the smallest
identifiable area of an
image
• Each pixel is a single
colour and is given a
binary value which
represents that colour
e.g. 111100000000
might equal red
• A pixel’s colour can be
changed by changing this value
1.2.3 Representation of Bitmap images
Resolution is the number of pixels in the image
High definition (HD) television uses a resolution of
1920 × 1080 pixels
The first iPhone had a resolution of 320 × 480 pixels
1.2.3 Representation of Bitmap images
Creating an image
0 0 0 0 1 0 0 0 0 0
• Each pixel is given a binary value
• Each value represents a different colour 0 0 0 1 1 0 0 0 0 0
• Using one bit per pixel allows only 2 values, 0 and 1
0 0 1 1 1 0 1 0 0 0
0 1 1 1 1 0 1 1 0 0
1 = Black, 0 = White 1 1 1 1 1 0 1 1 1 0
0 0 0 0 1 0 1 0 0 0
1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0
1.2.3 Representation of Bitmap images
More bits per pixel = more colour combinations
1 bit = 2 Colours 10 10
10 10 10 10
2 bits = 4 Colours
11 01 11 11 01
3 bits = 8 Colours
11 01 01 01 01 01
4 bits = 16 Colours 11 01 01 01 01 01
How many bits per pixel required for 256 colours? 11 01 01 11
11 01 01 11 11
11 01 01 01 01 01 01

01 = 10 =
00 = 11 =
1.2.3 Representation of Bitmap images
Colour depth (bit depth)
• Each pixel can represent a finite number of colours
• A pixel is attributed a number of n bits
• The number of combinations (2n) dictates the bit depth and therefore the number of colours that can be
represented
• A higher colour depth gives a greater range of colour and a better quality of image

8 bits per pixel = 28 = 256 colours


16 bits per pixel = 216 = 65,536 colours
24 bits per pixel = 224 = 16,777,216 colours
1.2.3 Representation of Bitmap images
Colours and resolution vs File Size
20 pixels

How does the number of colours affect


file size?

How does the resolution of the image


affect

20 pixels
file size?

8 colours
1.2.3 Representation of Bitmap images
Effects of varying colour depth
Changing the colour depth of an image will affect the number of colours it can display, as shown below:

2 Colours 4 Colours 8 Colours 16 Colours 256 Colours 16.7m Colours


1.2.3 Representation of Bitmap images
Representing a monochrome image in binary
A monochrome image can be represented in binary as a bit pattern
The following icon can be represented by the corresponding bit pattern:

0111,
0011,
0101,
1000
1.2.3 Representation of Bitmap images
Converting a bit pattern into a monochrome image
Convert the following bit pattern into an 8 × 8 icon:

00000011
00000101
00001010
01010100
01101000
00110000
01011000
10000000
1.2.3 Representation of Bitmap images
Converting a bit pattern into a monochrome image
Convert the following bit pattern into an 8 × 8 icon:

00000011
00000101
00001010
01010100
01101000
00110000
01011000
10000000
1.2.3 Representation of Bitmap images
Calculating file sizes of images

File size (bits) = image resolution × image depth

=8x8×8

= 512 bits

How many bytes?

= 512/8

= 64 bytes
1.3
Data Storage and File Compressions
Measurement of data storage
Bits and bytes
1.3.1
Many units are used for data storage in computers

1 bit = a single 0 or 1
1 byte = 8 bits = 1 character of text
1 nibble = 4 bits or half a byte
1 KiB (kibibyte) = 1024 bytes
1 MiB (mebibyte) = 1024 KiB
1 GiB (gibibyte) = 1024 MiB
1 TiB (tebibyte) = 1024 GiB
1 PiB (pebibyte) = 1024 TiB
1 EiB (exbibyte) = 1024 PiB
Measurement of data storage
Kibibyte or kilobyte?
1.3.1
All other unit prefixes work the same way
1 megabyte is 1000,000 bytes
1 kilobyte is 1000 bytes 1 mebibyte is 1,048,576 bytes (1024 x
1 kibibyte is 1024 bytes 1024)
Measurement of data storage
Base 10 system of units
1.3.1
Measurement of data storage
Base 2 system of units (IEC)
1.3.1
Units

One suggestion
Kites – kibi
Make - mebi
Great – gibi
Toy – tebi
Planes – pebi
for the
Elderly - exbi
Calculation of file sizes
Example 1:
1.3.2
A photograph is 1024x 1080 pixels and uses a colour depth of 32 bits. How many photographs
of this size would fit onto a memory stick of 64GiB?
Calculation of file sizes
Example 2:
1.3.2
A camera detector has an array of 2048 x2048 pixels and uses a colour depth of 16. find the
size of an image take by this camera in MiB.
Calculation of file sizes
Example 3:
1.3.2
An audio CD has a sample rate of 44100 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.
Calculation of file sizes 1.3.2
Calculation of file sizes 1.3.2
Data Compression 1.3.3
Compression techniques

Compression is the name given to algorithms which reduce file sizes


Decompression is the process where compressed data is restored to its original format

Compression is heavily used with sound, image and video files


Data Compression
Reduce (compress) the file sizes
1.3.3
We reduce the file sizes for the following reasons:

To save storage space on devices.


To reduce the time taken to stream a music or video file.
To reduce the time taken to upload, download or transfer a file across the network.
Using less bandwidth.
Reduces file size also reduces costs.
Data Compression 1.3.3
Lossless Compression
Lossy Compression

Permanently loses some data will not lose any of the original data
Ex: JPG, GIF, MP3,MP4 Ex: PNG, TIFF
Data Compression
Lossless Compression
1.3.3
Run-length-Encoding (RLE):

Can be used for lossless compression of a number of different formats

For example: if a run of notes for a sound file looked like this:

3As 5Bs 2Cs

This way, none of the data is lost but the file is compressed by the software finding efficient savings of data where
possible
Data Compression
Lossless Compression
1.3.3
Run-length-Encoding (RLE)
This icon could be represented in an uncompressed format where 1 = white and black = 0 as:
11110 11110 00000 00000 00000

Using RLE, how would the image be encoded?

4 w 1 b 4 w 16 b
4 1 1 0 4 1 16 0
Data Compression
Lossless Compression
1.3.3
Run-length-Encoding (RLE)
Data Compression
Lossless Compression
1.3.3
Run-length-Encoding (RLE)
Now you know what
happens when you
click a key in your
keyboard!

Exam- Like questions in your book P41

You might also like