Professional Documents
Culture Documents
Chapter 3
Chapter 3
Data Representation
and
The Number System
What is the meaning of
representation of data?
Data Representation refers to the
methods used internally to represent
or symbolize information stored in a
computer.
00000000 0 20 1
00000001 1 21 2
0010 2 22 4
0011 3 23 8
0100 4 24 16
0101 5 25 32
0110 6 26 64
0111 7 27 128
1000 8 28 256
00001001 9 29 512
00001010 10 210 1024
Conversion Among Bases
• The possibilities:
Decimal Octal
Binary Hexadecimal
Decimal to Decimal
Decimal Octal
Binary Hexadecimal
Next slide…
Weight
Base
Binary to Decimal
Decimal Octal
Binary Hexadecimal
Binary to Decimal
• Technique
–Multiply each bit by Nx2n-1, where N is
the “weight” of the bit
–n weight is the position of the bit,
starting from 0 on the right
–Add the results
Examples
1. (1011)2 = (1X23 )+(0X22)+(1X21) +(1X20)
= 8+0+2+1
= (11)10
3. (101100)2 =(1X25
)+(0X24)+(1X23)+(1X22)+(0X21)+(0X20)
=32+0+8+4+0+0
= (44)10
Binary to Decimal Conversion cont…
• The easiest method for converting a binary number to
its decimal equivalent is to use the Multiplication
Algorithm
Binary 1 0 1 0 1 1 0 1
x x x x x x x x
Positional Values 27 26 25 24 23 22 21 20
Products 128 + 0 + 32 + 0 + 8 + 4 + 0 +1
(173)10
Octal to Decimal
Decimal Octal
Binary Hexadecimal
Octal to Decimal
• Technique
– Multiply each bit by Nx8n-1, where N is the “weight” of the bit
– The n weight is the position of the bit, starting from 0 on the
right
– Add the results
Example
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by Nx16n-1, where n is the “weight” of the bit
– The weight is the position of the bit, starting from 0 on the right
– Add the results
Hexadecimal to Decimal Conversion
Convert 3B4F to its decimal equivalent:
Hex Digits
3 B 4 F
x x x x
Positional Values
163 162 161 160
Products 12288 +2816 + 64 +15
15,18310
Example
Decimal Octal
Binary Hexadecimal
Decimal to Binary Conversion
• The easiest way to convert a
decimal number to its binary
equivalent is to use the Division
Algorithm
• This method repeatedly divides a
decimal number by 2 and records
the remainder
–The remainder digits (a sequence of
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1
– Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Division Algorithm
Convert 67 to its binary equivalent:
6710 = x2
Step 1: 67 / 2 = 33 R 1 Divide 67 by 2. Record quotient in next row
1 0 0 0 0 1 12
Octal to Binary
Decimal Octal
Binary Hexadecimal
Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent binary
representation
Example
7058 = ?2
7 0 5
7058 = 1110001012
Hexadecimal to Binary
Decimal Octal
Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit equivalent binary
representation
Example
10AF16 = ?2
1 0 A F
10AF16 = 00010000101011112
Decimal to Octal
Decimal Octal
Binary Hexadecimal
Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder
Example
123410 = ?8
8 1234
8 154 2
8 19 2
8 2 3
0 2
123410 = 23228
Decimal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Decimal to Hexadecimal Conversion
Convert 83010 to its hexadecimal equivalent:
830 / 16 = 51 R14
51 / 16 = 3 R3 = E in Hex
3 / 16 = 0 R3
33E16
Example
123410 = ?16
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
Binary to Octal
Decimal Octal
Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8
1 3 2 7
10110101112 = 13278
Binary to Hexadecimal
Decimal Octal
Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Binary to Hexadecimal Conversion
• The easiest method for converting binary to hexadecimal is to use
a substitution code
• Each hex number converts to 4 binary digits
Example
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Octal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Octal to Hexadecimal
• Technique
– Use binary as an intermediary
Example
10768 = ?16
1 0 7 6
2 3 E
10768 = 23E16
Hexadecimal to Octal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8
1 F 0 C
1 7 4 1 4
1F0C16 = 174148
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
55 A B C
D 11100101 E F
G H 7013 I
J K L dAF
35
x 105
175
000
35
3675
pp. 39
Multiplication (2 of 3)
• Binary, two 1-bit values
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)
• Binary, two n-bit values
– As with decimal values
– E.g., 1110
x 1011
1110
1110
0000
1110
10011010
Fractions
• Decimal to decimal (just for fun)