0% found this document useful (0 votes)
15 views19 pages

Chapter 1 Data Representation

The document outlines a syllabus for understanding data representation in computing, covering number systems such as binary, denary, and hexadecimal, along with their conversions. It explains how computers process text, sound, and images by converting them into binary, and discusses data storage measurements and compression methods. Key concepts include binary addition, logical shifts, and the use of two's complement for representing integers.

Uploaded by

kaydbossilo2020
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)
15 views19 pages

Chapter 1 Data Representation

The document outlines a syllabus for understanding data representation in computing, covering number systems such as binary, denary, and hexadecimal, along with their conversions. It explains how computers process text, sound, and images by converting them into binary, and discusses data storage measurements and compression methods. Key concepts include binary addition, logical shifts, and the use of two's complement for representing integers.

Uploaded by

kaydbossilo2020
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/ 19

CS WITH

SK
Data Representation
Syllabus
1.1 Number Systems
1 Understand how and why computers use x Any form of data needs to be converted to
binary to represent all forms of data binary to be processed by a computer
x Data is processed using logic gates and
stored in registers
2 (a) Understand the denary, binary and x Denary is a base 10 system
hexadecimal number systems x Binary is a base 2 system
x Hexadecimal is a base 16 system
(b) Convert between x Values used will be integers only
(i) Positive denary and p positive
ositive binary x Conversions in both directions, e.g., denary
(ii) Positive denary a and
nd positive to binary or binary to denary
hexadecimal x Maximum binary number length of 16-bit
(iii) Positive hexadecimal
hexadede
ecimal aand
nd positive
binary
Understand
3 Undersrrsstand hhow
and ow aand
nd hexadecimal
d why hex
ex
exadec m l iiss x
eccim
imal AAreas
reas wi within
ithhin ccomputer
ompuute
om ter
er sc science
cieencce tthat
hat
usedd ass a bene beneficial
bee efi method
f cial metho
ho off data
ho
hod hexadecimal is used should be identified
representation
repres senta atit onn x Hexadecimal is easier for humans to
uunderstand
un
unde
nde
ders
rsta
rs tand tthan
ta binary,
hann bi
ha b naryy, as iitt iss a sshorter
bina
ina hort
ho rtter
representation of the binary
4 (a) Add
dd
d two positive 8-bit bina
nary integers
na
binary
(b) Understand the concept of ooverflow
verflow and x An overflow error will occur if the value is
why it occurs in binary addition
adddition greater than 255 in an 8-bit register
x A computer or a device has a predefined
limit that it can represent or store, for
example 16-bit
x An overflow error occurs when a value
outside this limit should be returned
5 Perform a logical binary shift on a positive x Perform logical left shifts
8-bit binary integer and understand the x Perform logical right shifts
effect this has on the positive binary integer x Perform multiple shifts
x Bits shifted from the end of the register are
lost and zeros are shifted in at the opposite
end of the register
x The positive binary integer is multiplied or
divided according to the shift performed

+92-335-8467840

[email protected]
CS WITH

SK
x The most significant bit(s) or least significant
bit(s) are lost
6 Use two’s complement to represent positive x Convert a positive binary or denary integer
and negative 8-bit binary integers to a two’s complement 8-bit integer and
vice versa
x Convert a negative binary or denary
integer to a two’s complement 8-bit integer
and vice versa
1.2 Text, Sound & Images
1 Understand how and why a computer x Text is converted to binary to be processed
represents text and the use of character by a computer
sets, including American standard code for x Unicode allows for a greater range of
information interchange (ASCII) and characters and symbols than ASCII,
Unicode including different languages and emojis
x Unicode requires more bits per character
than ASCII
2 Understand how and w hy a computer x
hy
why A sound wave is sampled for sound to be
represents sound, including
inncl
clud
din
ing tth
h effects of
he
the converted to binary, which is processed by
samp
plee rate
the sample rat
ate a
ate nd sa
and ssample
ample rresolution
esoluutio
ioon a coompputerr
computer
x The
Thhe sample
The samp
sa mple
mp llee rate
rate is the thhe number
numb
nu berr of
of samples
sa
samp
amp
m les
taken in a second
x The sample
The samp
sa mple
mp l resolution
le res
esol
olut
ol uttioon is the
utio he nnumber
umbe
um berr of
be o b its
bits
per sample
x The accuracy of the recording and the file
size increases as the sample rate and
resolution increase
3 Understand how and why a computer x An image is a series of pixels that are
represents an image, including the effects converted to binary, which is processed by
of the resolution and color depth a computer
x The resolution is the number of pixels in the
image
x The color depth is the number of bits used
to represent each color
x The file size and quality of the image
increases as the resolution and color depth
increase

+92-335-8467840

[email protected]
CS WITH

SK
1.3 Data Storage & Compression
1 Understand how data storage is measured x Including:
 bit
 nibble
 byte
 kibibyte (KiB)
 mebibyte (MiB)
 gibibyte (GiB)
 tebibyte (TiB)
 pebibyte (PiB)
 exbibyte (EiB)
x The amount of the previous denomination
present in the data storage size, e.g.,
 bits in a byte
 1024 mebibytes in a gibibyte
2 Calculate the file lee ssize
ize ofof an im
mage
image e fi
file
le and
nd x Answers
A sw
An wer must
ers muustt bee gi given
givven in the
he uunits
in th niits sspecified
pe
ecified
a sound
so
oun
und file,
file
fi lee, using
usin
inng information
innffo
ormationn given
give
ve
en inn the
he question
que
uest
s ion
ioon
x Information given may include:
 Image
Im
mag
agee re
resosolu
so luuttiion
resolution o a n ccolor
nd
and olor
ol orr d epth
ep
depth th
 Sound sample rate, resolution and
length of track
3 Understand the purpose of a nd need for x
and Compression exists to reduce the size of
data compression the file
x The impact of this is, e.g.,
 Less bandwidth required
 Less storage space required
 Shorter transmission time
4 Understand how files are compressed using x Lossless compression reduces the file size
lossy and lossless compression methods without permanent loss of data, e.g. run
length encoding (RLE)
x Lossy compression reduces the file size by
permanently removing data, e.g., reducing
resolution or color depth, reducing sample
rate or resolution

+92-335-8467840

[email protected]
CS WITH

SK

1.1 Number Systems


Binary Representation
The Binary Number System is the fundamental building component of every computer.
Because this system only, contains1’s and 0’s, it was chosen. Computers may be represented
using the binary system because they have countless millions of tiny "switches" that must be
in the ON or OFF position. When a switch is in the ON position, it is represented by 1 and
when it is in the OFF position, by 0.
Binary System
Binary Number System have only two digits i.e. 0 and 1, also known as Base 2 number
system because it has only 2 digits that is why it is represented using powers of 2.
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 1 1 1 0 0 1

Denary
D
Deenary
yNNumber
um
mbe
b r SSystem
ystem
Denary
Deenary NNumber
umberr SSystem
um uses
ystem use es digits from 0 – 9 and their combinations, also known as Base
10
1 0 number
num b r system.
umbe e . It countss in
syysttem in multiple
mul ple of
ultititipl
ple
pl o 10’s
10’’s such
c as
such as 10,
10, 100,
0 1000
100, 100
00 and so oon.
and n.
104 1 3
10 102 101 100
10000 1000
10
000 100 10 1
3 5 7 4 2

Binary To Denary Conversion


In order, to convert Binary to Denary we have to multiply Binary Number to the powers of
2.

For Example: (10110111) 2 ื (?) 10


27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 1 1 0 1 1 1

1 ൈ 27 + 0 ൈ 26 + 1 ൈ 25 + 1 ൈ 24 + 0 ൈ 23 + 1 ൈ 22 + 1 ൈ 21 + 1 ൈ 20

1 ൈ 128 + 0 ൈ 64 + 1 ൈ 32 + 1 ൈ 16 + 0 ൈ 8 + 1 ൈ 4 + 1 ൈ 2 + 1 ൈ 1
128 + 0 + 32 + 16 + 0 + 4 + 2 + 1 = 183

+92-335-8467840

[email protected]
CS WITH

SK
3$*(

(10110111) 2 ื (183) 10
Denary to Binary Conversion
There are two methods to convert Denary Number to Binary Number.
Method 1
In this method, subtract the largest possible power of 2 and keep doing this until the value
0 is reached. This will give us the following 8-bit binary number:

For Example: (152) 10 ื (?) 2


152 – 128 = 24; 24 – 16 = 8; 8 – 8 = 0
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 0 1 1 0 0 0

(152) 10 ื (?) 2

Method 2
Inn this
thi
his method
method
oddw e successive
we vve
ely divide
successively divvid
idee the
the number
nuumbe
ber by
y22,, un
uuntil
ntitilil th
he rremainder
the ema
main
innde
der iss 0
der 0.. Re
RRead
ead
d the
remama
main
a nde
ders
remainders rs ffrom
rom
ro
om top to bot ttom.
bottom.

FFor
Fo Example:
or Ex
xam 173) 10 ื ((?)
le:: ((173)
ampl
ple:
pl 17 ?) 2

2 173 1
2 86 0
2 43 1
2 21 1
2 10 0
2 5 1
2 2 0
1
(173) 10 ื (10101101) 2

Hexadecimal System
Hexadecimal Number System is based on 16 different digits (0 – 9, A – F), also known as
Base 16. A to F are used to represent (hex) digits i.e. A = 10; B = 11, C = 12; D = 13;
E = 14; F = 15.
164 163 162 161 160
65536 4096 255 16 1
3 2 A C 5

+92-335-8467840

[email protected]
CS WITH

SK
As we know, 16 = 24 this means 1 hex digit is equal to 4 binary digits.
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 10 A
1011 11 B
1100 12 C
1101 13 D
1110
11110
10 14 E
1111
1
111
111
11 15 F

Binary
B
Binary
y tto
o He
Hexadecimal
ex
xaade
d cimal
To convert
con vertt Binary
onvert Binarry Number to
to Hexadecimal Number we split the bits into groups of 4 bits,
and
a
annnd convert
d co
onvnveert it iinto
ert
er n o Hexadeci
nt Hexadecimal
cima
ci al Number
Numb
Nu e and
mber
mb er and if
if number
numb
nu er of
mber
mb of bits
bits is
bi is not
not a multiple
mul
ultitipl
ulti ple of 4 w
ple
pl we
e can
add
ad
dd 0’ 0’s
0 ’s too tthe
h left.
he

010) 2 ื (?) 16
For Example: (101111100010)
(1011111000
00
0
1 0 1 1 1 1 1 0 0 0 1 0
8 4 2 1 8 4 2 1 8 4 2 1
8 + 2 + 1 = 11 8 + 4 + 2 = 14 2
B E 2

(101111100010) 2 ื (BE2) 16
Hexadecimal to Binary
For converting Hexadecimal to Binary, take each Hexadecimal digit and write down the 4-
bit code corresponding to the digit.

For Example: (D9F) 16 ื (?) 2


D 9 F
8 4 2 1 8 4 2 1 8 4 2 1
1 1 0 1 1 0 0 1 1 1 1 1

+92-335-8467840

[email protected]
CS WITH

SK
Hexadecimal to Denary
For converting Hexadecimal to Denary multiply it with the respective power of 16.

For Example: (8BE) 16 ื (?) 10


8 B E
162 161 160
256 16 1
8 ൈ 256 = 2048 11 ൈ 16 = 176 1 ൈ 14 = 14

2048 + 176 + 14 = 2238

(8BE) 16 ื (2238) 10
Denary to Hexadecimal
To convert Denary Numberer to Hexadecimal Number successive division by 16 until 0 is
er
reached. Remainders from b ottom to top to get the Hexadecimal Number
bottom

2) 100 ื ((?)
For Example: (2322)
(2322 ?) 16

16 2334
23344 14 = E
16 145
14
145 1
9
((2322)
(232
3 10 ื ((91E)
22)) 10 91EE) 16
91

Uses
Us
ses o
off H
Hexadecimal
exadecimal SSystem
ystem
Hexadecimal System is eas
easier
sier to use as 1 hex digit = 4 binary digits.
Address
Internet Protocol (IP) Addre
ess
Each device connected to a network is given an unique address known as the Internet
Protocol (IP) Address. 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). IPv4 has updated by the adoption of
IPv6. An IPv6 address is a 128-bit number broken down into 16-bit chunks, represented by
a hexadecimal number. For example: FDEC:BA98:7654:3210:ADFC:BDFF:2990:FFFF
Error Codes
Hex is often used in error messages on your computer. The hex number refers to the memory
location (In computing, this is an address in the primary memory where data values are
stored) of the error. This helps programmers to find and then fix problems.
Media Access Control (MAC) Address
All network adapters and network devices have a Media Access Control (MAC) address.
This is also known as the 'physical address' and is a unique address determined during the

+92-335-8467840

[email protected]
CS WITH

SK
manufacture of each device. This address is given as a set of 6 pairs of hexadecimal
numbers. An example of a MAC address would be: A0-1D-48-FE-5E-F5. You can determine
the physical address of the network adapters in a computer running the Windows operating
system by typing the following command in to a command prompt: ipconfig/all.
Hyper Text Markup Language (HTML) Color Code
HTML is a markup language that is used for processing, definition and presentation of text
like size of the text, color, bold, italic etc. It uses <tags>.
HTML is often used to represent colors of text on the computer screen. All colors can be
made up of different combinations of the three primary colors (red, green and blue). The
different intensity of each color (red, green and blue) is determined by its hexadecimal
value. This means different hexadecimal values represent different colors using the format
#RRGGBB. # symbol represents that the number written in hex form. This system uses two
hex digits to represent a single color e.g. #FA6200.
There are a possible 256 vvalues
alues for red, 256 values for green and 256 values for blue
256
giving a total of 256 x 25
56 x 256 (i.e. 16 777 216) possible colors.

Addition of Bin
Binary
nary D
Digits
ig
gits
Two
Tw
wo Bi
Bit Ad
Bit A
Addition
dditi
dition
on
n
1st Bit
Bt
Bi 2ndd Bit Bit Addition Sum Carry
0 0 0+0 0 0
0 1 0+1 1 0
1 0 1+0 1 0
1 1 1+1 0 1

Three Bit Addition


1st Bit 2nd Bit 3rd Bit Bit Addition Sum Carry
0 0 0 0+0+0 0 0
0 0 1 0+0+1 1 0
0 1 0 0+1+0 1 0
0 1 1 0+1+1 0 1
1 0 0 1+0+0 1 0
1 0 1 1+0+1 0 1
1 1 0 1+1+0 0 1
1 1 1 1+1+1 1 1

+92-335-8467840

[email protected]
CS WITH

SK
Example: Add (11001110) 2 + (00100011) 2
1st no 1 1 0 0 1 1 1 0
2nd no 0 0 1 0 0 0 1 1
Sum 1 1 1 0 1 1 0 1
Carry 0 0 0 0 0 0 1 0

Overflow
This type of addition generates an extra bit (9th bit) which shows that sum has exceeded its
value and is also known as Overflow Error and also represents that this number is too large
to be stored in computer using 8 bits.
Example: Add 111 + 223 (01101111) 2 + (11011111) 2
1st no 0 1 1 0 1 1 1 1
2nd no 1 1 0 1 1 1 1 1
Sum 1 0 1 0 0 1 1 1 0
Carry 1 1 1 1 1 1 1 1

Logical
Log
giccal B
Binary
inary
y SShifts
hifts
Comp
Computers
C put
uterrs ca
cann ccarry
arry out a llogical
ogical shift on a sequence of binary numbers. The logical shift
meeans
means ns moving
movivinnng
vi g the
the binary number
number to the left or to the right. Each shift left is equivalent to
nu
mu
m ultltip
ltip plyyinng th
multiplying thee bi
b nary numbe
binary ber by 2 a
be
number nd eeach
and acch sh
a shif
ift
if
f ri
shift righ
ghtt iss eequivalent
gh
right quiv
quival
iv a ent
alennt to divid
iv idin
id
din
ing
dividing g th
he bi
the bin
nary
binary
numb
number
mber
mb er by
by 2.2. If
If any place is
is empty fill it with 0. But we can shift only to certain extent after
which it will contain 0’s onlyy and that would result in the generation of error message.
Example: (00011111) 2 = ((31)
31) 10
Most Significant Bit is the lef
left-most
ft-most bit.
128 64 32 16 8 4 2 1
0 0 0 1 1 1 1 1

Now, fill the empty place left after shift is 0.


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

(00111110) 2 = (62) 10 ฺ 31 ൈ 21

Two places shift on the left


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

+92-335-8467840

[email protected]
CS WITH

SK
(01111100) 2 = (124) 10 ฺ 31 ൈ 22

Three places shift on the left


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

(11111000) 2 = (248) 10 ฺ 31 ൈ 23

Four places shift on the left


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

(11110000) 2 = (240) 10 ് 31 ൈ 24
The left-most 1-bit has lost which means it has exceeded its limit which results in error.

Two’s Complement
For representing negative
neg
egat
eg attiv
atiive numbers
nnuu we take the most significant bit negative
Example:
Exam
mpl e: (11000110)
plle:
e: (110
(1
(110
000
001
110) 2
11

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

-128
-12
28 + 64
4 + 4 + 2 = (-58
(-58)
8)2

To take Two’s Complement


nt we need to invert the bits and then add ‘1’ to LSB (Least
nt
Significant Bit).

Example: (01111110)2 = (126)10

Step 1: Invert all the bits


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

Step 2: Add 1 to LSB


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

(-126)10

+92-335-8467840

[email protected]
CS WITH

SK
3$*(

1.2 Text, Sound & Images


Character Sets
Every word is made up of symbols or characters. When you press a key on a keyboard, a
number is generated that represents the symbol for that key. This is called a character code.
A complete collection of characters is a character set.
Text and numbers can be encoded in a computer as patterns of binary digits. Hexadecimal
is a shortcut for representing binary. ASCII and Unicode are important character sets that
are used as standard.
ASCII
The ASCII character set is a 7-bit set of codes that allows 128 different characters. That is
enough for every upper-case letter, lower-case letter, digit and punctuation mark on most
keyboards. ASCII is only used for the English language.
Extended ASCII uses 8-bit co ccodes
des (0 to 255 in denary or 0 to FF in hexadecimal). This gives
another 128 codes to a allow
llllow
lo
oww for characters in non-English alphabets and for some graphical
included:
characters to be inc
clu
lude
ed:
dec hex oct char dec hex oct char dec hex oct char dec hex oct char
0 0 000 NULL 32 20 040 space 64 40 100 @ 96 60 140 ‘
1 1 001 SOH 33 21 041 ! 65 41 101 A 97 61 141 a
2 2 002 STX 34 22 042 “ 66 42 102 B 98 62 142 b
3 3 003 ETX 35 23 043 # 67 43 103 C 99 63 143 c
4 4 004 EOT 36 24 044 $ 68 44 104 D 100 64 144 d
5 5 005 ENQ 37 25 045 % 69 45 105 E 101 65 145 e
6 6 006 ACK 38 26 046 & 70 46 106 F 102 66 146 f
7 7 007 BEL 39 27 047 ‘ 71 47 107 G 103 67 147 g
8 8 010 BS 40 28 050 ( 72 48 110 H 104 68 150 h
9 9 011 TAB 41 29 051 ) 73 49 111 I 105 69 151 i
10 a 012 LF 42 2a 052 * 74 4a 112 J 106 6a 152 j
11 b 013 VT 43 2b 053 + 75 4b 113 K 107 6b 153 k
12 c 014 FF 44 2c 054 ’ 76 4c 114 L 108 6c 154 l
13 d 015 CR 45 2d 055 , 77 4d 115 M 109 6d 155 m
14 e 016 SO 46 2e 056 . 78 4e 116 N 110 6e 156 n
15 f 017 SI 47 2f 057 / 79 4f 117 O 111 6f 157 o
16 10 020 DLE 48 30 060 0 80 50 120 P 112 70 160 p
17 11 021 DC1 49 31 061 1 81 51 121 Q 113 71 161 q
18 12 022 DC2 50 32 062 2 82 52 122 R 114 72 162 r
19 13 023 DC3 51 33 063 3 83 53 123 S 115 73 163 s
20 14 024 DC4 52 34 064 4 84 54 124 T 116 74 164 t
21 15 025 NAK 53 35 065 5 85 55 125 U 117 75 165 u
22 16 026 SYN 54 36 066 6 86 56 126 V 118 76 166 v
23 17 027 ETB 55 37 067 7 87 57 127 W 119 77 167 w
24 18 030 CAN 56 38 070 8 88 58 130 X 120 78 170 x
25 19 031 EM 57 39 071 9 89 59 131 Y 121 79 171 y
36 1a 032 SUB 58 3a 072 : 90 5a 132 Z 122 7a 172 z
27 1b 033 ESC 59 3b 073 ; 91 5b 133 [ 123 7b 173 (
28 1c 034 FS 60 3c 074 < 92 5c 134 \ 124 7c 174 |
29 1d 035 GS 61 3d 075 = 93 5d 135 ] 125 7d 175 )
30 1e 036 RS 62 3e 076 > 94 5e 136 ^ 126 7e 176 -
31 1f 037 US 63 3f 077 ? 95 5f 137 _ 127 7f 177 DEL

Unicode
Unicode can represent all languages of the world, thus supporting many operating systems,
search engines and internet browsers used globally. There is overlap with standard ASCII

+92-335-8467840

[email protected]
CS WITH

SK
code, since the first 128 (English) characters are the same, but Unicode can support several
thousand different characters in total. It will support up to four bytes per character.
The Unicode consortium was set up in 1991. Version 1.0 was published with five goals; these
were to:
 Create a universal standard that covered all languages and all writing systems
 Produce a more efficient coding system than ASCII
 Adopt uniform encoding where each character is encoded as 16-bit or 32-bit code
 Create unambiguous encoding where each 16-bit and 32-bit value always represents
the same character
 Reserve part of the code for private use to enable a user to assign codes for their own
characters and symbols (useful for Chinese and Japanese character sets, for example).

Representation of Sound
Soundwaves are vibrations in the air. The human ear senses these vibrations and interprets
them as sound. Each sound wave has a frequency, wavelength and amplitude. The amplitude
specifies the loudness of the sound.

+92-335-8467840

[email protected]
CS WITH

SK
Sound waves vary continuously. This means that sound is analogue. Computers cannot work
with analogue data, so sound waves need to be sampled in order to be stored in a
computer. Sampling means measuring the amplitude of the sound wave. This is done using
an analogue to digital converter (ADC).
To convert the analogue data to digital, the sound waves are sampled at regular time
intervals. The amplitude of the sound cannot be measured precisely, so approximate values
are stored.

Sampling Resolutio
Resolution: Number
on: N mber of bit per sample. It is also known as bit depth.
um
Sampling
Samp
pling Rate
ng R atte
Itt iiss th
the number
he nu
umber
mb ssamples
berr of sound saamples taken per second. Measured in Hertz (Hz). 1 Hz means
onee sample
sa
amplle per
mple per second.
sec
e ond.
Higher
Highher
Hi er the
he sampling
the samp ing rate, greater
ampl
pl ter the
grreatte
g ter the file
le size.
fille
fi siz
i e.
Pros
1. Larger dynamic range
2. Better sound quality
3. Less sound distortion
Cons
1. Produces larger file size
2. Takes longer to transmit/download music files
3. Requires greater processing power
CDs have a 16-bit sampling resolution and a 44.1kHz sample rate - that is 44100 samples
every second. This gives high-quality sound reproduction.

Representation of Bitmap Images


Bitmap Images are made up of Pixels (Picture elements); an image is made up of a two-
dimensional matrix of a Pixel. Pixels can take different shapes such as:

+92-335-8467840

[email protected]
CS WITH

SK

Each Pixel can be represented as Binary Number, and so bitmap image is stored in a
computer as a series of binary numbers, so that:
 A black and white image only requires 1 bit per pixel – this mean that each pixel can
be of one of two colors, representing 1 or 0.
 If each pixel is represented by 2 bits, then each pixel can be of one of four colors (22
= 4) representing the FOUR combinations of 0 & 1 i.e. 00, 01, 10, 11.
 If each pixel is represe
ent
n ed by 3 bits, then each pixel can be of one of four colors (23
represented
= 8) representing the EI
EEIGHT
IGHT combinations of 0 & 1 i.e. 000, 001, 010, 011, 100, 101,
110, 111.
Color Depth
Each
Ea ch ccolor
ach olo
ol orr iiss re
represented
epr
pres
essented by number
by nummbe bits.
b r off b Ann 8-bit
itis. A bit color
8-b depth
color dep
pth means
th m eans tthat
ans hatt ea pixel
each piixxel can
bee one
b nee ooff 256
25 56 ccolors (because
olors (bec cause 2 = 256). Modern computers have
ca 8 have a 24-bit color depth,
whic
icch means
which meeanns overoverr 16 million
millioon different colors can be represented.
IImage
Im
Imag
magge Re
R e olu
esoluti
tiion refers too thee nnumber
Resolution umbe
um b r off pixels
be pix
ixel
els
ls that
thhatt m ake
ak
ke up a
make ann im
iimage;
age;
age; ffor
or eexample,
xamp
xa mple
mplee, an
ag
a
imagge co
image ccontains
ont
ntains 4096 × 30 072 pixels (12,582,912 pixels in total).
3072

Drawback of using high resolution images is the increase in file size. As the number of pixels
used to represent the image is increased, the size of the file will also increase. It impacts on
the time to download an image from the internet or the time to transfer images from device
to device. A certain amount of reduction in resolution of an image is possible before the loss
of quality becomes noticeable.

+92-335-8467840

[email protected]
CS WITH

SK
1.3 Data Storage & Compression
Measurement of Data Storage
Bit (Binary Digit): Basic Unit of all computing memory storage terms and is either 1 or 0.
Byte: Smallest memory unit (1 byte = 8 bits).
Name of Memory Size Equivalent Denary Values
Kilobyte (KB) 103 Bytes
Megabyte (MB) 106 Bytes
Gigabyte (GB) 109 Bytes
Terabyte (TB) 1012 Bytes
Petabyte (PB) 1015 Bytes
Exabyte (EB) 1018 Bytes

The above system of numbering now only refers to some storage devices but is technically
inaccurate. It is based on the
he SI (base 10) system of units. 1 TB hard disk drive would allow
he
the storage of 1 ൈ 1012 byt
bytes
yttes
y t according to this system.
measured
Memory size is measu suureed inn terms of powers of 2, another system has been adopted by the
al Electrotechnical
IEC (International Ele
lect
c rotech
ct al Commission)
chnica
ch ca C mm
Co mis onn) that
i sion thhatt is
is based
b seed on the
ba e binary
the inarry system.
bin
inar syst
stem..
st
Name
Na
ame
me ofof Memory
Me
Me Size
Sizze Number
Nu
umb
mber
mbeer ofof Bytes
Byte
Bytees Equivalent
Equi
Eq uiiva
vale
lent
lentt D
Denary
enarry V
enar
en Value
alue
Kilobyte
Kilo
Kilooby
byte (KiB) 210 Bytes 1024 Bytes
Megabyte
Mega
Me g by
ga yte
t (MiB) 210 Bytes 1048576 Bytes
Gigabyte
Giga
Gi gaaby
b te (GiB) 2300 BBytes
ytes
ytes 1073741824
1073
10 073
7374
7418
74 1824
18 24 BBytes
ytes
ytess
TTerabyte
Te
era
rabyte (TiB) 240 Bytes 1099511627776 Bytes
Petabyte (PiB) 250 Bytes 1125899906842624 Bytes
Exabyte (EiB) 260 Bytes 1152921504606846976 Bytes

This system is more accurate.


accurate
e. Internal memories (such as RAM and ROM) should be measured
using the IEC system. A 64GiB RAM store 64 x 230 bytes of data (68 719476 736 bytes).
Calculation of File Size
Calculation of the file size required to hold a bitmap image and a sound sample.
File Size of Image = Image Resolution (In Pixels) ൈ Color Depth (In Bits)
Size of Mono Sound File = Sample Rate (In Hz) ൈ Sample Resolution in Bits ൈ Length of
Sample (In Seconds)
Stereo sound file, multiply the result by two.

+92-335-8467840

[email protected]
CS WITH

SK
Example
A photograph is 1024 ൈ 1080 pixels and uses a color depth of 32 bits. How many
photographs of this size would fit onto a memory stick of 64 GB.
Multiply number of pixels in vertical and horizontal directions to find total number of pixels
= [1024 ൈ 1080] = 1 150 920 Pixels.
Multiply number of pixels by color depth then divide by 8 to give the number of bytes = 1
105 920 ൈ 32 = 35 389 440/8 bytes = 4 423 680 bytes.
64 GB = 64 ൈ 1024 ൈ 1024 = 68 719 476 736 bytes.
Divide the memory stick size by the file size = 68 719 476 736/4 = 423 680 = 15 534
photos.
Data Compression
Sound and Image files can be b sometimes very large. It is necessary to reduce (or compress)
the size of a file for the following
folllowing reasons:
 To save storage sp spa
pac
ace oonn devices such as the hard disk drive/solid state drive
space
 To reduce th the
he ttime
imee taken
e too stream
en st a music
u icc orr video
mus vi file
fiile » to
to reduce the time taken to
uplo
up load
ad,, do
upload, d ownwnllo
downloadload or trransfer
transfererr a fille a
file croossss a nnetwork
across ettwoorkk
 The
The download/upload
down
ownlo
wnnlo
l ada /upload process esss uses
procces es up
up network
netw
ne orkk bandwidth
wor band
ba dwiidt dth - this
thhis is the
is th maximum
he ma
maxi imum rate
m ra
rat
te of
transf
ansf
sfer
fer ooff data
transfer da acrosss a network, measured in bits per second. This occurs whenever a
da
file
fi e is downloaded,
is do
d ownlooaded, forr eexample,
dow xam
ampl
am
mpl e, ffrom
ple, ro
om a se server.
servrver
rverr. Compressed
Comp
Co mpre
mp reesse files
s ed filles contain
con
ontaainn fewer
ta fewer bits
ewer biti s of
data
data
da ta tthan
h n un
ha uuncompressed
ncompressed d files and therefore use less bandwidth, which results in a faster
data
da
daataa ttransfer
ta ransfer rate.
 Reduced file size also reducesreduces costs. For example, when using cloud storage, the cost is
based on the size of the e files stored. Internet Service Provider (ISP) may charge a user
based on the amount off data downloaded.

Lossy & Lossless File Compression


Two types of File Compression: Lossy & Lossless

Lossy File Compression


This removes unnecessary data from the file. Original File cannot be retrieved after
compression (loss of some details). This technique have to decide which part to keep and
which one remove.
For example, Applying a lossy file compression algorithm to:
 An image, it may reduce the resolution and/or the bit/colour depth.
 A sound file, it may reduce the sampling rate and/or the resolution.

+92-335-8467840

[email protected]
CS WITH

SK
Lossy Files are smaller in comparison to Lossless Files and benefits storage and data transfer
rate.
Some of Lossy Files Compression algorithms are: MP3, MP4, JPEG
MP3
When Internet file-sharing boomed into popularity with Napster and the iPod, the MP3
cornered the market for one reason: it had a small footprint. Without broadband
connections, it was impractical at the time to share file sizes larger than the MP3 standard
2 – 3 Megabytes. And that preference has stuck for some time now even though MP3 does
not have nearly the same amount of quality as WAV or AIFF files. Despite this growing base
of people using higher quality formats, there are still those who prefer the So, if you have
a slower internet connection or limited hard drive space, MP3 could be your file format of
choice. If you’re worried about quality loss, don’t fret too much about it. While, yes, there is
a noticeable drop off in sound quality, MP3 files fall square under the “good enough”
umbrella.
MP4
This format allowss tthe storage
he stora
he rra
a
age of multimedia files rather than just sound - music, videos,
photos and ani animation
nim
ni matition
onn can a allll b
be stored
e st
stooredd iinn th
the MP4
he MP
M 4 foformat.
form
r at
at.t. As w with MP3,
itith MP
M this
3,, thi
3 i a llossy
is is o syy file
os
compression
co
om
mp pre
pre
r ssssioon foformat,
mat, but it sstill
orm till rretains
etai
et
tai
ai s a
ains ann acc
acceptable
c ep
ccepta
ab quality
blle qu
q uallitityy of ssound
qual ound
ou daand d vvideo.
nd ideo
id eoo. Mo
Movies,
example,
for ex ample,, ccould
xampl ould be streamed
stre
eamed over the internet using the MP4 format without losing any
real
rea
all d
a discernible
issce
erni
rnniib
ble qquality.
u lity.
ua
JJPEG
PEG
EG
G
When a camera takes a ph photograph,
hotograph, it produces a raw bitmap file which can be very large
in size. These files are temporary
tempo
po
p orary in nature. JPEG is a lossy file compression algorithm used
for bitmap images. As withh MP3, once the image is subjected to the JPEG compression
formed
algorithm, a new file is forme
m d and the original file can no longer be constructed.
 Human eyes don't detect differences in color shades quite as well as they detect
differences in image brightness (the eye is less sensitive to color variations than it is to
variations in brightness)
 Separating pixel color from brightness, images can be split into 8x8 pixel blocks, for
example, which then allows certain 'information' to be discarded from the image without
causing any real noticeable deterioration in quality.

Lossless File Compression


In this type of Compression original file can be retrieved from the compressed one. This is
beneficial for the crucial data, files, applications etc. None of the details is lost.

+92-335-8467840

[email protected]
CS WITH

SK
Run Length Encoding (RLE)
Run Length Encoding (RLE) can be used for lossless compression of a number of different file
formats:
RLE on Text Data
Consider the following text string: 'aaabbbbccccddddd'. Assuming each character requires
lbyte then this string needs 16 bytes. If we assume ASCII code is being used, then the string
can be coded as follows:

a a a b b b b c c c c d d d d d
03 97 04 98 04 99 05 100

a = 97; b = 98; c = 99; d = 100


2nd number represents ‘no of times’ digit is occurring.
One Problem can be encou encountered
untered with a string such as 'cdcdcdcdcd' where RLE compression
isn't very effective. Too copecope with this, we use a flag. A flag preceding data indicates that
what follows are the hee nnumber
umbe er of repeating units (for example, 255 05 97 where 255 is the
flag and the oother
therr ttwo
th wo
w o numbbers iindicate
numbers ndic
nd
dicate
ic e th
ic tthat
att tthere
h re a
he re fi
are ffive
vee iitems
t ms w
te itih AS
with ASCCII co
ASCII od e 9
code 7). Wh
7)
97). W
Whenen
a flag ag is
ffllag
lag is not
not used,
u ed
us d, the next xt byte(s)
by
yte(
yt are
e(sss)) are taken
e tak
akken wiwith
ithh their
theeir face
heir face value
aluee and
va annd a rurun
un ooff 1 (for
mpl
example,
exam ple,
e,, 01 99
01 99 means one e character with ASCII code 99 follows).
aaaaaaaa
aa
aaaaaaaa bb
bbbbbbbbbb
bbbbbbbbb
b c d c d c d eeeeeeee
08 9
08 977 10 98 01 99 01 100 01 99 01 100 01 99 01 100 08 101

The original string contains 3


322 characters and would occupy 32 bytes of storage.
The coded version contains 1
188 values and would require 18 bytes of storage.
Flag is introduced of 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. This is a reduction in
file size of about 53% when compared to the original string.

+92-335-8467840

[email protected]
CS WITH

SK
Example 1: Black & White Images

Example 2: Colored Images

2R, 2G,3B
3B, 4R
7G
4B,3R
4G,3B
4R, 3G
2B,3G,2R

RRLE
Thee RLLE co de hhas
code as 92 values,
value
es, which means the compressed file will be 92 bytes in size. This
gives
vees a file
give file reduction of about
fil
fi bout 52%. It should be noted that the file reductions in reality will
ab
not be as large as this due ttoo other data which needs to be stored with the compressed file
(e.g. a file header).

+92-335-8467840

[email protected]

You might also like