Unit 1-Data Representation
Unit 1-Data Representation
Chapter 1
By Farah Khaleeq
Data
7 6 5 4 3 2 1 0
2 2 2 2 2 2 2 2
128 64 32 16 8 4 2 1
Why Binary ?
• Since the computer is made up of electronic Components; it can have
only two states, either
• On(1)
• Off(0)
• The data which is given to the computer is converted into binary form
because a computer understands only binary language.
Converting Binary Numbers To Denary
Binary number is 10010101
1.Draw the following table using powers of 2
7 6 5 4 3 2 1 0
2 2 2 2 2 2 2 2
128 64 32 16 8 4 2 1
128 64 32 16 8 4 2 1
Answers
a. 51
b. 127
c. 153
d. 116
e. 255
Denary To binary : Method 1
• Place 1 in the appropriate positions so the total becomes the denary
number:
• To convert 107 into binary place 1 in the columns 64,32,8,4,2 and 1
because and fill rest of the columns with 0 because
107=64+32+8+2+1
128 64 32 16 8 4 2 1
0 1 1 0 1 0 1 1
Decimal to Binary :Successive Division :
Method 2
Answer
Binary number is : 11001
Page 7. C.W(a-e) H.W(f-j)
a. 101001
b. 1000011
c. 1010110
d. 1100100
e. 1101111
Uses of Binary numbers
The microprocessor makes use of transistors that identify voltage levels only i.e.
‘1’ for ‘on’ and ‘0’ for ‘off ’ . That’s why binary numbers are used.
Binary numbers are used in registers. A register is a small piece of memory
where values can be held.
In a digital instrument, a register might be used to convey whether the device is
sending a signal to the computer, 1 or 0.
For example, a robot arm that has various motors to perform different
operation, for example , raise the arm, open the grip and close the grip. Each
motor works via a signal, 1 for on, 0 for off. A register is used for each motor to
convey the signal.
The Hexadecimal System
17
Page 9. C.W(a-e) H.W(f-j)
a. C3
b. F7
c. 27F
d. 4EE
e. 1E1
Hexadecimal To Binary
For each hex number write equivalent binary number by using the tables given below
(i.e. writing 1’s below the numbers which add up to make the given hex number)
8 4 2 1 8 4 2 1
0 1 0 1 1 1 0 1
5 D is 13
19
Page 10. C.W(a-e) H.W(f-j)
a. 01101100
b. 01011001
c. 10101010
d. 10100000000
e. 010000001110
Why hexadecimal numbers
are used instead of Binary?
21
Converting Hexadecimal To Denary
a. 107
b. 156
c. 74
d. 255
e. 511
Converting Denary to
Hexadecimal
To convert from denary to hexadecimal involves successive division by 16 until the
value “0” is reached. The only addition to the algorithm when converting from
denary to hexadecimal is that a table must be used to obtain the hexadecimal digit
if the remainder is greater than decimal 9.
24
Denary to Hexadecimal
Conversion
16 423
16 26 7
16 1 10(A) Hexadecimal Number= 1A7
0 1
25
Denary to Hexadecimal
Conversion : Example
1054 16 65 E (14)
65 16 4 1
4 16 0 4
Hexadecimal Number : 41EF
26
Page 12. C.W(a-e) H.W(f-j)
a. 62
b. E3
c. 1EA
d. 1FF
e. 33A
Uses of the hexadecimal numbers
Error codes
Media Access Control
IPv6 addresses
HTML colour codes
28
Error Codes
• Error codes refer to the memory location of the error and
automatically generated by the computers.
• These error codes are often shown in hexadecimal values.
• The programmer needs to know how to interpret error codes
Error Codes from a Windows System
Media Access Control(MAC)
• Apple corporation(001CB3)
31
Internet Protocol (IP) Addresses
a. 10000011
b. 01100110
c. 01111011
d. 1011011
e. 01101111
Page 16. C.W(a-e) H.W(f-j)
a. 01110001(113)
b. 01110101(117)
c. 10010101(149)
d. 11011110(222)
e. 10010111(151)
Overflow error
• Overflow errors happen when the largest number that a register can hold
is exceeded. The number of bits that it can handle is called the word size.
• Most CPUs use a much bigger word size than 8 bits.
• The greater number of bits which can be used to represent a number then
the larger number that can be stored.
• A 16-bit register would allow a maximum denary value 65535(216 −1)
Classwork C.W Act 1.10
2b. 10111001111100100
Logical Binary shifts
a. 104
b. 26 number is divided
by 22
c. 15
d. 240 number is
multiplied by 24
Home Work [ Act 1.11 pg. 20]
Submission : Before next class
Two’s complement
Example 3 pg. 22
Convert 01101110 in two’s complement binary into denary
-128 64 32 16 8 4 2 1
Example 4 pg. 23
Convert 00111111 in 2’s complement binary into denary
-128 64 32 16 8 4 2 1
Classwork Act 1.12 pg. 23
1. Convert the following positive denary numbers into 8-bit binary
numbers in 2’s complement format:
a. 39
b. 66
e. 111
f. 125
a. 00100111
b. 01000010
e. 01101111
f. 01111101
Classwork Act 1.12 pg. 23
a. 85
b. 51
c. 76
d. 126
Writing Negative binary numbers in two’s complement format
Classwork Act 1.13 pg. 25
a. 11101110
b. 11100001
c. 11010001
d. 11000001
e. 10101000
f. 10100100
g. 10011100
h. 11111111
i. 11110000
j. 10000001
Homework Act 1.14 pg. 25
1.2.1 Character Set
• The list of binary codes that can be recognised by computers
as being usable characters.
• Text and numbers can be encoded in a computer as patterns
of binary digits. Hexadecimal is a shortcut for representing
binary.
• Types of character sets
1. ASCII code
2. Unicode
ASCII CODE
97
65
Disadvantages of ASCII
Image Type Bits per pixel Possible colours each Bit combinations
pixel has
Black And White 1 2 0 or 1
Coloured 2 4 00, 01, 10, 11
Coloured 3 8 000,001, 010,…….,
111
Colour Depth
Image ‘A’ has the highest resolution and É’has the lowest resolution
Drawbacks of using high resolution images
BitA basic unit of computer storage (is either 1 or 0). The word
comes from binary digit.
ByteSmallest unit of memory in a computer. 1 bytes = 8 bits
Nibble it has 4 bits – half a byte
1 byte of memory wouldn’t allow to store much information so
memory size is measured in multiples
1.3.1 Measurement of data storage
CDs have a 16bit sampling resolution and 44.1 kHz sample rate,
which is 44100 samples per second
Calculating The Size Of An Audio File
There are four main pieces of data that are used in calculating the size of
an audio file:
• The length of the audio track (this needs to be in seconds)
• The number of samples taken per second (sample rate)
• The number of bits used to store each sample (sample depth)
• The number of channels used to play the track (mono has 1, stereo has 2)
• following calculation can then be carried out to find the size of the file:
Formula to calculate Audio file size
File size = sample rate x sample depth x track length x number of tracks
For example, for an image that has a main background colour that is
the same throughout the image, a compression method will recognise
that there are a lot of pixels that all have the same value and collate
them.
This means they will be stored as a single data value with further data
that records the pattern.
Audio Compression Using Lossless
Compression
• When the music track is played, the full track, exactly as it
was recorded, can be reconstructed and listened to.
• People may use lossless compression when downloading a
music track if they want the highest quality possible and to
hear the track exactly as it was recorded.
Run-Length Encoding(RLE)
• RLE can be used for lossless compression of a number of different file
formats
Using Run-Length Encoding on Text Data
• Compress the string ‘aaaaabbbbccddddd’
• No. of characters = 16
• Storage = 16 Byte
• RLE code storage = 8 bytes
Characters ASCII code Number of time
a 97 (1 byte) 05 (1 byte)
b 98 (1 byte) 04 (1 byte)
c 99 (1 byte) 02 (1 byte)
d 100 (1 byte) 05 (1 byte)
Total = 8bytes 4 bytes 4bytes
Using RLE with Images: Black & White
Coloured Image