Data Representation
Data Representation
• What is Data ?
• Number System
• Types of Number System
– Decimal
– Binary
– Octal
– Hexadecimal
Numbering Systems
• A number system is a method to represent
(write) numbers.
• Every number system has a set of unique
characters or literals.
• The count of these literals is called the radix or
base of the number system.
Numbering Systems
3 6 5 2 . 1 4
MSD LSD
MSB LSB
• 310 = 112
• 410 = 1002
• 610 = 1102
• 1010 = 10102
0.37510 = ? 0.0112
0.375 * 2 = 0.750 0
0.75 * 2 = 1.50 1
0.50 * 2 = 1.00 1
Solve :
• 0.812510 = 0.11012
• 0.1562510 = 0.001012
Binary ↔ Decimal Conversion
11.2510
23 22 21 20 . 2-1 2-2
1 0 1 1 . 0 1
8 4 2 1 0.5 0.25
Solve :
• 1001012 = 3710
• 1101012 = 5310
Octal Number System
• Base 8
• Consists 0 – 7 digits
• Value based on the position of the digits
(positional-value system)
• 3714.01
83 82 81 80 . 8-1 8-2
3 7 1 4 . 0 1
MSB LSB
• 710 = 078
• 810 = 108
• 1210 = 148
• 1810 = 228
• 00, 01, 02,03,04,05,06,07, 10, 11, 12, 13, 14, 15, 16,
17, 20, 21, …….,77, 100 , 101, 102……..
Decimal to Octal Conversion
11710 = ? 1658
8 117
8 14 5 Solve :
8 1 6 • 673.110 = 1241.063148
0 1 • 149810 = 27328
Octal to Decimal Conversion
84 83 82 81 80
1 0 2 6 3
8 4 2 1
Solve :
• 3728 = 25010
• 24.68 = 20.7510
• 20208 = 104010
Octal to Binary Conversion
• Converting from octal to binary has a very
straightforward method because octal numbers
are shortened versions of binary strings.
• Remember that each octal digit represents three
binary digits. Therefore, one octal digit should
give three binary digits (bits).
• Octal can be converted to binary indirectly (first
to decimal, then to binary).
Octal to Binary Conversion
7 2 5
• 7258 = 111 010 1012
• 372.158 = 011 111 010 . 001 1012
Solve :
• 4368 = 100 011 1102
• 14.18 = 001 100 . 0012
Octal to Binary Conversion
A direct method to convert octal to binary with steps is as follows:
• Write down the octal number separating the digits. Each octal digit
represents three binary digits and therefore is equal to a power of 2. The
rightmost digit equals to 20 (1), the next one equals to 21 (2) and the
leftmost one equals to 22 (4). Write these numbers (4, 2 and 1) below the
octal digits.
• Step 2: Determine which powers of two (4, 2 or 1) sum up to your octal
digits. For example, if one of your octal numbers is 6, this means 4 and 2
sum up to 6 (and 1 is not used). If your octal number is 2, only 2 is used; 4
and 1 are not.
• Step 3: Write down 1 below those 4, 2 and 1’s that are used. Write down 0
below those that are not used.
• Step 4: Read 1’s and 0’s you just wrote from left to right. You will get your
binary number.
• 1110101012 = 7258
• 11111010 . 011012 = 372.328
Solve :
• 1001011 . 110112 = 113.668
• 10101111002 = 12748
Hexadecimal Number System
• Base 16
• Hexadecimal Number System is a base-16 numeral system used
in diverse fields, especially in computing and digital electronics.
• Consists 0 – 9 digits, A-F characters
• Value based on the position of the digits (positional-value
system)
• B2C.1
MSB LSB
• 1010 = 0A16
• 1510 = 0F16
• 1810 = 1216
• 2610 = 1A16
• 00, 01, 02,…, 09, 0A, 0B, 0C, 0D, 0E, 0F, 10, 11, 12,
13……F0, F1,…. FF, 100, 101,....
Decimal to Hexadecimal Conversion
11710 = ? 7516
16 117
16 7 5 Solve :
0 7 • 4610 = 2E16
• 15310 = 9916
• 286010 = B2C16
Hexadecimal to Decimal Conversion
164 163 162 161 160
1 2 C 5 B
8 4 2 1
Solve :
• 1D916 = 47310
• 80E116 = 3299310
• 10CE16 = 430210
Hexadecimal to Binary Conversion
2 D 5
• 2D516 = 0010 1101 01012
• 8EF16 = 0100 1110 11112
Solve :
• 4FA16 = 0100 1111 10102
• 2C116 = 0010 1100 00012
Binary to Hexadecimal Conversion
• 10101110102 = 2BA16
• 11101100101001.110112 = 3B29.D816
Solve :
• 11110 . 010112 = 1E.5816
• 11101000110101102 = E8D616
Hexadecimal to Octal Conversion
• 2D516 = 0010 1101 01012
= 001 011 010 1012 = 13258
• 8EF16 = 0100 1110 11112
= 010 011 101 1112 = 23578
Solve :
• 4FA16 = 23728
• A2DE16 = 1213368
Octal to Hexadecimal Conversion
• 13258 = 001 011 010 1012
= 0010 1101 01012 = 2D516
• 23578 = 010 011 101 1112
= 0100 1110 11112 = 8EF16
Solve :
• 15738 = 37B16
• 13018 = 2C116
In a nut-shell
• Conversion from Decimal to other Number Systems
Step 1: Divide the given number by the base value (b) of the
number system in which it is to be converted.
Step 3: Keep on dividing the quotient by the base value and note
the remainder till the quotient is zero.
1 + 1 + 1 = 11
?
Practice Questions
• Add the following binary numbers:
a. 1010 + 1001
b. 100110 + 110101
c. 101101 + 111101
d. 1110.110 + 1010.011
Binary Representation of Integers
• Binary number can be represented only by using
0’s and 1’s, but can not use the sign (-) to denote
the negative number or sign (+) to denote the
positive number.
• So it must be either 0 or 1.
• There are three methods to represent binary
number. They are
Magnitude Complement
1’s 2’s
Unsigned Signed
complement complement
Signed Integer Representation
• Sign and Magnitude:
– MSB denotes the sign ( 0 for +ve, 1 for –ve)
1 1 1 1 0 1 1 1
-7 +7
Sign & Magnitude
Negative Positive
• 0 0000
• -1 • 1 0001
• -2 • 2 0010
• -3 • 3 0011
• -4 • 4 0100
• -5 • 5 0101
• -6 • 6 0110
• -7 • 7 0111
Addition with S & M
(using 4 bits)
• 7 + (-3)
• (-4) + 1
• 5 + (-5)
Addition with S & M
(using 8 bits)
• 7 + (-3)
• (-24) + 16
Addition / Subtraction
Sign Magnitude Numbers
One’s Complement Representation
00011000 11100111
+ 00010000 + 00010000
------------------------- ----------------------------
00011000 11100111
+ 11101111 + 11101111
-------------------------- ----------------------------
Two’s Complement Representation
• +ve numbers - True form / normal representation
• -ve numbers –
– Convert to 1’s complement (Flip 0 to 1 and 1 to 0)
– Add 1
00011000 00011000
+ 00010000 + 11110000
------------------------- ----------------------------
11101000 11101000
+ 00010000 + 11110000
-------------------------- ----------------------------
Practice Questions
• Add -25 and -35 using 1’s complement
• Add -46 and 25 using 2’s complement
Signed Binary numbers
in a nutshell
• In Binary number
Signed Binary Number
• A carry occurring for the left most bit (ie, creating a result
1 bit larger than the initial numbers) may be discarded.
• The number of bits used for each pixel determines how many
colours we can use. This is known as the colour depth.
• The more bits per pixel (bpp) the greater the colour depth and the
more bits we need to store the image
– Colour depth
– File format
• A larger colour depth and resolution = higher quality image + larger file size
• A smaller colour depth and resolution = lower quality image + smaller file size
Representation of Data Sound
• Sound waves are analogue, which means
continuously changing.
• For eg:
• A ⬄ 065(ascii) ⬄ 41 (hex) ⬄ 100 0001
• 1 ⬄ 049(ascii) ⬄ 31 (hex) ⬄ 011 0001
1. Represent © (U-00A9)
Binary: 000 1010 1001
1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 1
2. Represent ɸ (U-0278)
Binary: 010 0111 1000
1 1 0 0 1 0 0 1 1 0 1 1 1 0 0 0
UTF-8 3-Octet
1 1 1 0 1 0
1 0
1. Represent ಆ (U-0C86)
Binary: 0000 1100 1000 0110
1 1 1 0 0 0 0 0 1 0 1 1 0 0 1 0
1 0 0 0 0 1 1 0
2. Represent ◑ (U-25D1)
Binary: 0010 0101 1101 0001
1 1 1 0 0 0 1 0 1 0 0 1 0 1 1 1
1 0 0 1 0 0 0 1
Practice Questions
• Represent the following in UTF-8 encoding:
▪ £ (U-00A3)
▪ ↔ (U-2194)
▪ } (U-007D)
UTF-32
• UTF-32 is a fixed length encoding scheme that
uses exactly 4 bytes to represent all Unicode
code points.
• It directly stores the binary code of any Unicode
code point in 4 bytes.
• Symbol $ [ Unicode code Point : U+0024,
Binary code: 00100100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0
Summary
• ASCII was the first major encoding.
– Because of computer limitations it was only 1 byte.
• Unicode was invented to address the problem
of encoding more languages than just English.
• UTF-8 is a variable length encoding.
• UTF 8 is now the most dominant encoding for
the World Wide Web and accounts for roughly
98% of all web pages.
• UTF-32 is fixed length encoding.