1
CHAPTER 2:
2.1 DATA REPRESENTATION
ON CPU
SUMMARY: This topic introduces the numbering systems: decimal, binary, octal
and hexadecimal. The topic covers the conversion between numbering systems,
binary arithmetic, one's complement, two's complement, signed number and
coding system. This topic also covers the digital logic components.
CLO 2:apply appropriate method to solve arithmetic problem in numbering
system (C3).
2
1. Define decimal, binary, octal and hexadecimal number.
2. Perform arithmetic operation (addition and subtraction) in
different number bases.
3. Convert decimal, binary, octal and hexadecimal numbers
to different bases and vice-versa.
4. Describe the coding system:
a) Sign and magnitude
b) 1st complement and 2’s complement
c) Binary coded decimal (BCD system)
d) ASCII code
3
4
5
6
INTRODUCTION
• The binary system and decimal system is most important
in digital system.
• Decimal - Universally used to represent quantities outside
a digital system.
• Its means, there will be situations decimal values must be
converted to binary values before entered to digital
system.
• Example : Calculator / Computer
7
DECIMAL NUMBERING SYSTEM(10 DIGIT)
• Decimal system is composed of 10 numerals or symbols.
These 10 sysmbols are 0, 1, 2, 3, 4, 5, 6,
7, 8, 9.
Using these symbols as digits of a number,
it can express any quantity.
8
DECIMAL NUMBERING SYSTEM(10 DIGIT)
• Base number = 10
• Basic number = 0,1,2,3,4,5,6,7,8,9
Basic number
23410
Base number
9
Addition Decimal Numbers
Example: 45710 + 24510
L3 L2 L1
4 5 710
+ 2 4 510
L1 = 7 + 5 =12 – 10 = 2
7 0 210 L2 = 5 + 4 = 9 + 1 -10 = 0
L3 = 4 + 2 = 6 + 1 = 7
10
Subtraction Decimal Numbers
• Example: 45710 - 24510
L3 L2 L1
4 5 710
- 2 6 510 L1 = 7 - 5 = 2
L2 = 5 +10 – 6 =9
1 9 210
L3 = 3 – 2 = 1
11
BINARY NUMBERING SYSTEM (2 DIGIT)
• Base number = 2
• Basic number = 0,1
Basic number
10112
Base number
Define Binary numbers
-Binary numbers representing number in which only digits 0 or 1.
12
Basic binary addition rule
13
• Example :
101 + 101 = 1010
1011 + 1011 = ?
14
Exercise
• Ex 1:
110112 + 100012 =
1 1 0 1 1
+ 1 0 0 0 1
10 1 1 0 0
Ex 2:
101112 + 1112 = ________
1 0 1 1 1
+ 1 1 1
1 1 1 1 0
15
Subtraction
Four conditions in binary subtraction
16
Exercise
• Ex 1:
10012 – 102 = 1112
1 0 0 1
- 0 1
1
1
0
1
• Ex 2:
1010112 – 11112 =__________
1 0 1 0 1 1
- 0 1
1
1
1
1
1
0
1
0
17
Octal Numbering System ( 8 Digit )
• Base number = 8
• Basic number = 0,1,2,3,4,5,6,7
Basic number
2568
Base number
18
19
Octal number - Addition
• Ex: Ex:
1238 4578
+ 3218 + 2458
4448
20
Octal number - (Subtraction)
• Ex: Ex:
5248 – 1678 = 3358 5248
- 1678
Ex:
1678
- 248
21
Hexadecimal Numbering System
( 16 Digit )
• The hexadecimal number system uses base 16.
• It has 16 possible digit symbols.
• It uses the digits 0 through 9 plus the letters A, B, C, D, E
and F as the 16 digit symbols.
Basic number
7A16 Base number
22
Hexadecimal number - Addition
• Ex: Ex:
3 316 2 0 D 316
+ 4 716 + 1 2 B C16
7 A16
23
Hexadecimal number - Subtraction
Ex: Ex:
4 416 3 2 5 516
- 1 716 - 3 1 8 216
2 D16
24
1. Solve the problems below:
a) 1010102 + 1100112
b) 11110002 +1011002
c) 011101002 – 001111102
d) 11002 – 01112
e) 758 +568
f) 6228- 2678
g) DF16 + AC16
h) 84516 -2A616
i) C316 - 0B16
25
converting
26
Formula Converting Between Number
Bases
a) 2 to10 : a x 2n + b x 2n-1 + c x 2n-2 + …….
10 to 2: base 10 divide 2
b) 2 to 8: 001
100
101
1 4 5
8 to 2: 4 5
100 101
c) 2 to 16 : 1110
1001
14 9
16 to 2: 3 A
0011 1010
27
d) 8 to10 : a x 8n + b x 8n-1 + c x 8n-2 + …….
10 to 8 : base 10 divide 8
e) 16 to 10 : a x 16n + b x 16n-1 + c x 16n-2 +…..
10 to 16 : base 10 divide 16
f) 8 to 16 : either 8 to 10 to 16 or 8 to 2 to 16
16 to 8 : 16 to 2 to 8 or 16 to 10 to 8
28
Step of conversion
numbering system
30
31
32
Conversions Between Base Number
Binary (2) to Decimal (10) conversions
33
Binary (2) to Decimal (10) conversions
Example : 1 1 0 1 12
= (1x24 )+ (1x23) + (0x 22 ) + ( 1x21 ) + (1x20 )
= 16 + 8 + 0+2 + 1
= 2710
34
Ex:
1011. 1102 base 10
= (1x23)+ (0x22)+(1x21)+(1x20) + (1x2-1)+(1x2 2)+(0 x 2-3)
= 8+0+2+1+0.5+0.25+0
= 11.75
35
1. 11111. 0102 base 10
Ans: 31.25
2. 11101. 1102 base 10
Ans:29.75
36
Convert the decimal number 169.9 to binary
• Interger part 169 • Interger part 0.9
2|169 0. 9 x2
2|84 ----1 1. 8x2
2|42 ----0 1. 6x2
2|21 ----0 1. 2 x2
2|5 -----1 0. 4 x 2
2|2 ----0 0. 8x2
2|1 _-----0 1. 6 x2
2|0 -----1 1. 2 x2
0. 4 x2
0. 8x2
1. 6x 2
169.9 = 1001001.11100 2
37
Decimal (10) to Binary (2) conversions
Convert 25 into binary number
10
2 25
25 = 110012
10
2 ______ 1 LSB
12
2 ______ 0
6
2 3 ______ 0
______ 1
2 1
0 ______ 1 MSB
38
• Convert 40.25 into binary number
10
2 40
2 20 ______ 0 LSB 0.25 x 2 = 0.5
______ 0
0.5 x 2 = 1.0
2 10
2 5 ______ 0
______ 1
2 4
2 2 ______ 0 MSB
0 ______ 1
Ans: 101000. 01 2
39
1. Convert 3010 into binary number
Ans: 111102
2. Convert 51.1210 into binary number
Ans:110011.00012
40
Octal (8) –to-decimal(10) conversion
• The octal number system has a base of eight, meaning
that it has eight possible digits: 0,1,2,3,4,5,6 and 7.
• The digit positions in an octal number have weights as
follows :
84 83 82 81 80 • . 8-1 8-2 8-3
1 1 1
¿ 1 ¿ 2 ¿ 3
8 8 8
41
Octal (8) –to-decimal(10) conversion
• Convert 3728 to decimal number
2 1 0
3788 = 3 x (8 ) + 7 x (8 ) + 2 x (8 )
= (3 x 64) + (7x 8) + (2 x 1)
= 25010
42
• Convert 1150.538 to decimal number
= 1 x (83) +1 x (82) + 5 x (81) + 0 x (80)+ 5x (8-1)+3 x (8-2)
= (1 x 512) + (1x 64) + (5 x 8)+ 0+ 0.625+0.047
= 616.67210
43
• 6348 base 10
Ans: 41210
• 325.628base 10
Ans: 213.7810
44
Decimal(10)-to-Octal(8) Conversion
• Decimal integer can be converted to octal by using the
same repeated-division method with a division factor of 8.
• Convert 891 10 into octal number
8 891
8 ______ 3 LSB
111
8 ______ 7
13
8 1 ______ 5
______ 1
0 MSB
Ans: 1573 8
45
Convert the decimal number 169.9 to octal
• Interger part 169 • Interger part 0.9
8|169 0. 9 x8
8|21 ----1 7. 2 x8
8|2 -----5 1. 6 x8
|0 -----2 4. 8 x8
6. 4 x 8
3. 2 x 8
1. 6 x8
4. 8 x8
6. 4 x8
3. 2 x8
1. 6x8
169.9 = 251.71463 8
46
• 41210 base 8
Ans: 6348
• 213.78 10 base 8
Ans: 325.6178
47
Octal(8) –to- Binary (2) conversion
48
Binary(2) to Octal (8)conversion
49
• Convert 75728 into binary number
Ans: 1111011110102
• Convert 5468 into binary number
Ans: 1011001102
50
• Convert 1010111112 into octal number
Ans: 5378
• Convert 1101110110002 into octal number
Ans: 67308
51
Hexadecimal(16)-To-Decimal(10)
Conversion
• A hexadecimal number can be converted to its decimal
equivalent by using the fact that each hex digit position
has a weight that is a power of 16.
52
Hexa (16) –to-decimal(10) conversion
= (2x16x16)+(14x16)+(6)+(10/16)+(3/(16x16))
= 512+ 224+6+0.625+ 0.0117
= 742.6367
53
• Ex 1:
1416 = (1 x 161) + (4 x 160)
= 16 + 4
= 2010
54
• Ex 2:
ABC16 = (10 x 162) + (11 x 161)+ (12 x 160)
= 2560 + 176 + 12
= 274810
55
• Convert 2516 into decimal number
Ans: 3710
• Convert 138.C7AE16 into decimal number
Ans: 312.7810
56
Decimal(10)-To-Hexadecimal(16) Conversion
• Decimal to hex conversion can be done using repeated
division by 16.
• Ex: Convert 2010 to hex
2010 = 1416
16 20 LSB
16 1 4
0 1
MSB
57
Convert the decimal number 169.9 to hexadecimal
• Interger part 169 • Interger part 0.9
16|169 0. 9 x16
16|10 --- 9 14. 4 x 16
0 ---10--A 6. 4 x 16
6. 4 x 16
169.9 = A9.E6 8
58
• Convert 2510 into hex number
Ans: 1916
• Convert 125.2510 into hex number
Ans: 7D.416
59
Hexadecimal (16)-to-Binary(2) Conversion
• Like the octal number system, the hexadecimal number
system is used primarily as a “shorthand” method for
representing binary numbers.
• It is a relatively simple matter to convert a hex number to
binary .
• Each hex digit is converted to its four-bit binary
equivalent.
60
Ex :
• Convert 9F2 16 into binary number
9 F 2
1001 1111 0010
9F2 16 = 1001111100102
61
Ex :
• Convert ABF.3 16 into binary number
A B F .3
1010 1011 1111 .0011
ABF.3 16 = 101010111111.00112
62
Binary(2)-to-Hexadecimal(16) Conversion
• The binary number is grouped into groups of four bits,
and each group is converted to its equivalent hex
digit.
• Zero are added, as needed to complete a four-bit
group.
• Ex:
1012 = 0101
= 516
63
• Ex:
111010012 = __________
00101101001111002 =___________
64
• Convert 4DA .516 into binary number
Ans: 010011011010.01012
• Convert 87E 16 into binary number
Ans: 1000011111102
65
• Convert 111100001010.101011 2 into hex
number
Ans: F0A.AC2
• Convert 0101110011102 into hex number
Ans: 5CE2
66
Exercises
• Convert the decimal number 140.3 to
a) binary number
b) octal number
c) hexadecimal
67
• Convert 0.9687510 to hexadecimal
0. 96875 x16
15. 5 x 16
8. 0 x 16
0. 0 x 16
0.96875 = 0.F816
68
• Convert 0.F816 to decimal
0 x161 + 15x16-1 + 8x16-2
= 0.9375 +0.03125
0.F816 = 0.96875
69
Summary
70
2.1.4 Describe the coding system
a. Sign and magnitude
b. 1’s Complement and 2’s Complement
c. Binary Coded Decimal (BCD system)
d. ASCII and EBCDIC
71
a. Sign and Magnitude
• In an 8 bit word, signed magnitude representation
places the absolute value of the number in the 7
bits to the right of the sign bit,
• For example in 8 bit sign magnitude,
• Positive 3 is : 0000 0011
• Negative 3 is: 10000011
72
b. One’s Complements and Two’s
Complements
• One’s Complements
• One’s complements is used in binary number.
• The one’s complement of a binary number is obtained
by changing each 0 to 1 and 1 to a 0.
• Only change negative number
• In other words, change each bit in the number to its
complement.
73
Example:
How can we represent the number -510 in 1's complement using 8 bit.
1)Write the positive value of the number in binary.
+ 5= 0101
2)Write in 8 bit number.
+ 5= 00000101 -------- 8 bit number
3)Reverse each bit of the number so 1's become 0's and 0's become 1's
00000101 11111010
-5 = 11111010 (1st complement)
74
Example
a) Convert +2710 to 1’s complement
b) Convert -2710 to 1’s complement
Solution (a)
1) Write the positive value of the number in binary.
+2710 = 110112
2) Write in 8 bit number
110112 = 00011011 ( 1 ‘st complement )
75
Solution (b)
1) Write the positive value of the number in binary.
+ 27= 110112
2)Write in 8 bit number.
+ 27= 00011011 -------- 8 bit number
3) Reverse each bit of the number so 1's become 0's and 0's
become 1's
00011011 11100100
-27 = 11100100 (1st complement)
76
EXERCISE 2.2.2
Solve the problem below:
1. Convert +4510 to 1’s complement
2. Convert -4510 to 1’s complement
3. Convert +1610 to 1’s complement
4. Convert -1610 to 1’s complement
77
Two’s Complement
• For positive number 2’s complement is the same as
binary number.
• For negative number 2’s complement is the reversal of
binary number and adding 1 to the least-significant-bit.
Two’s complement = One’s Complement + 1
78
Example
How can we represent the number -510 in 2's complement
using 8-bits
1)First, we write the positive value of the number in
binary.
+ 5= 01012
2)Write in 8 bit number
+ 5= 01012 = 00000101 -----8 bit
3) Next, we reverse each bit to get the 1's complement
00000101 11111010 ---------1st complement
79
• 4) Last, we add 1 to the number.
80
EXERCISE 2.2.2
Solve the problem below:
1. Convert +2610 to 2’s complement
2. Convert -2610 to 2’s complement
3. Convert +910 to 2’s complement
4. Convert -910 to 2’s complement
5. -19 +15 using 2’s complement number. Show all steps.
6. +12 +(– 9) using 2’s complement number. Show all
steps.
81
1. Convert the number below to 1’s complement and 2’s
complement.
i. -101110012 Ans: 01000110 ( 1st comp)
01000111(2nd comp)
ii. -5768
Ans: 010000001 ( 1st comp)
iii. -124516 010000010 (2nd comp)
iv. -1310 Ans: 1110110110111010 ( 1st comp)
1110110110111011 (2nd comp)
Ans: 0010 ( 1st comp)
0011 (2nd comp)
82
c. BCD Code
• BCD – Binary Coded Decimal
• It’s contain BCD 8421, 2421, 3321, 5421, 5311, 4221
and etc.
• The common used is BCD 8421 and BCD 2421.
83
Step of conversion
84
4 bit BCD Code
Desimal 5421 5311 4221 3321 2421 8421 7421
0 0000 0000 0000 0000 0000 0000 0000
1 0001 0001 0001 0001 0001 0001 0001
2 0010 0011 0010 0010 0010 0010 0010
3 0011 0100 0011 0011 0011 0011 0011
4 0100 0101 1000 0101 0100 0100 0100
5 1000 1000 0111 1010 1011 0101 0101
6 1001 1001 1100 1100 1100 0110 0110
7 1010 1011 1101 1101 1101 0111 1000
8 1011 1100 1110 1110 1110 1000 1001
9 1100 1101 1111 1111 1111 1001 1010
85
Binary-Coded-Decimal Code
• If each digit of a decimal number is represented by its
binary equivalent, the result is a code called binary-
coded-decimal.
• Decimal digit can be as large as 9, four bits are
required to code each digit (the binary code for 9
is 1001)
86
• Exp: 87410
8 7 4 (decimal)
1000 0111 0100 (BCD)
87
BCD 8421 Code – to – Binary Number
• Ex:
Convert 1001 0110BCD 8421 to binary number.
Step 1: Change BCD 8421 code to decimal
number.
1001 0110
9 6
Step 2 : Change decimal number to binary
number.
1001 0110BCD 8421 = 11000002
88
Binary Number – to – BCD 8421 Code
• Ex:
Convert 10010102 to BCD 8421
code.
Step 1: Change binary number to decimal
number.
10010102 = 7410
Step 2: Change decimal number to BCD
8421 code.
10010102 = 01110100BCD 8421
89
Exercises
1. Convert :
a) 28516 into BCD number
b) 3008 into BCD number
c) 10101002 into BCD number
d) 0011 1000 011BCD into hexadecimal
e) 0010 0000 0010 0000BCD into hexadecimal
f) 0011 0101BCD into binary
90
d. ASCII Code
• The most widely used alphanumeric code is the
American Standard Code for Information Interchange
(ASCII).
• The ASCII code is a seven-bit code and so it has 27
= 128 possible code groups.
• ASCII code is used to represent data internally in
personal computers.
91
ASCII code MSB
LSB
Binary 000 001 010 011 100 101 110 111
Binary Hex 0 1 2 3 4 5 6 7
0000 0 Nul Del sp 0 @ P p
0001 1 Soh Dc1 1 1 A Q a q
Read:
0010 2 Stx Dc2 “ 2 B R b r
• x-axis. y-axis 0011 3 Etx Dc3 # 3 C S c s
0100 4 Eot Dc4 $ 4 D T d t
0101 5 End Nak % 5 E U e u
0110 6 Ack Syn & 6 F V f v
0111 7 Bel Etb ‘ 7 G W g w
1000 8 Bs Can ( 8 H X h x
1001 9 HT Em ) 9 I Y i y
1010 A LF Sub . : J Z j z
1011 B VT Esc + ; K k
1100 C FF FS , < L l
1101 D CR GS - = M m
1110 E SO RS . > N n
1111 F SI US / ? O o
92
Ex:
An operator is typing in a BASIC program at the keyboard of
certain microcomputer. The computer converts each keystroke into
its ASCII code and stores the code as a byte in memory.
Determine the binary strings that will be entered into memory
when operator types in the following BASIC statement:
GOTO 25
93
• Solution:
Locate each character (including the space) and record ASCII
code.
G 01000111
O 01001111
T 01010100
O 01001111
(space) 00100000
2 00110010
5 00110101
*0 was added to the leftmost bit of each ASCII code because the
Codes must be stored as bytes (eight bits).
94
[Link] following message encode in ASCII code. What the
meaning of this code ?
a) 54 4F 4C 4F 4E 47
b) 48 45 4C 4C 4F
c) 41 50 41 4B 48 41 42 41 52
95
How the character sent from the keyboard
to the computer?
• Step 1: The user presses the letter T key on
the keyboard.
• Step 2: An electronic signed the letter T and
sent to system unit.
• Step 3: The signed for letter T is converted to
its ASCII code and stored in memory
for processing.
• Step 4: The binary code for the letter T is
converted to an image on the output
device.
96
Tutorial
1. Convert 6148 into decimal value
2. Convert 8310 into octal value
3. Convert 24.68 into decimal value
4. Convert 25010 into octal value
5. Convert following binary numbers into decimal value:
a) 0011002
b) 0000112
c) 0111002
d) 1111002
e) 11100.0112
97
6. Convert following decimal numbers into binary value:
a) 64
b) 500
c) 34.75
d) 25.25
e) 27.1875
98
7. Convert the following binary number into decimal
number:
a) 001100
b) 000011
c) 011100
d) 111111
e) 11100.011
f) 110011.10011
8 . Covert the following hexadecimal number into decimal
number:
a) D52
b) ABCD
c) 67E
d) F.4
e) 888.8
f) EBA.C
99
9. Convert the following binary number into hexadecimal
number:
a) 1001.1111
b) 10000.1
c) 110101.011001
10. Convert the following sign decimal number into 2’s
complement:
d) +13
e) +110
f) -25
100
11. Convert the following 2’s complement into sign decimal
number :
a) 0111 0000
b) 0001 1111
c) 1101 1001
12. Convert the following BCD number into decimal
number:
d) 1010
e) 0001 0111
f) 1000 0110
g) 0101 0100 0011
h) 0011 0010. 1001 0100
101
13. Convert the following decimal number into BCD number:
a) 6
b) 13
c) 99.9
d) 872.8
e) 145.6