2.1 Data Representation On Cpu: SUMMARY: This Topic Introduces The Numbering Systems: Decimal, Binary, Octal
2.1 Data Representation On Cpu: SUMMARY: This Topic Introduces The Numbering Systems: Decimal, Binary, Octal
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.
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
• Base number = 10
• Basic number = 0,1,2,3,4,5,6,7,8,9
Basic number
23410
Base number
9
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
4 5 710
- 2 6 510 L1 = 7 - 5 = 2
L2 = 5 +10 – 6 =9
1 9 210
L3 = 3 – 2 = 1
11
• Base number = 2
• Basic number = 0,1
Basic number
10112
Base number
• Example :
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
Basic number
2568
Base number
18
19
Ex:
1678
- 248
21
Basic number
7A16 Base number
22
• Ex: Ex:
3 316 2 0 D 316
+ 4 716 + 1 2 B C16
7 A16
23
Ex: Ex:
4 416 3 2 5 516
- 1 716 - 3 1 8 216
2 D16
24
converting
26
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
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
Example : 1 1 0 1 12
Ex:
1011. 1102 base 10
Ans: 31.25
2. 11101. 1102 base 10
Ans:29.75
36
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
2 25
25 = 110012
10
2 ______ 1 LSB
12
2 ______ 0
6
2 3 ______ 0
______ 1
2 1
0 ______ 1 MSB
38
2 40
2 5 ______ 0
______ 1
2 4
2 2 ______ 0 MSB
0 ______ 1
Ans: 101000. 01 2
39
Ans: 111102
2. Convert 51.1210 into binary number
Ans:110011.00012
40
1 1 1
¿ 1 ¿ 2 ¿ 3
8 8 8
41
2 1 0
3788 = 3 x (8 ) + 7 x (8 ) + 2 x (8 )
= (3 x 64) + (7x 8) + (2 x 1)
= 25010
42
• 6348 base 10
Ans: 41210
• 325.628base 10
Ans: 213.7810
44
Decimal(10)-to-Octal(8) Conversion
8 891
8 ______ 3 LSB
111
8 ______ 7
13
8 1 ______ 5
______ 1
0 MSB
Ans: 1573 8
45
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
Ans: 1111011110102
Ans: 1011001102
50
Ans: 5378
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
= (2x16x16)+(14x16)+(6)+(10/16)+(3/(16x16))
= 742.6367
53
• Ex 1:
1416 = (1 x 161) + (4 x 160)
= 16 + 4
= 2010
54
• Ex 2:
Ans: 3710
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
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
Ans: 1916
Ans: 7D.416
59
Ex :
9 F 2
9F2 16 = 1001111100102
61
Ex :
A B F .3
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
Ans: 010011011010.01012
Ans: 1000011111102
65
Ans: F0A.AC2
Ans: 5CE2
66
Exercises
• Convert the decimal number 140.3 to
a) binary number
b) octal number
c) hexadecimal
67
0. 96875 x16
15. 5 x 16
8. 0 x 16
0. 0 x 16
0.96875 = 0.F816
68
= 0.9375 +0.03125
0.F816 = 0.96875
69
Summary
70
Example:
How can we represent the number -510 in 1's complement using 8 bit.
+ 5= 0101
3)Reverse each bit of the number so 1's become 0's and 0's become 1's
00000101 11111010
Example
a) Convert +2710 to 1’s complement
b) Convert -2710 to 1’s complement
Solution (a)
Solution (b)
1) Write the positive value of the number in binary.
+ 27= 110112
3) Reverse each bit of the number so 1's become 0's and 0's
become 1's
00011011 11100100
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.
Example
How can we represent the number -510 in 2's complement
using 8-bits
+ 5= 01012
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
c. BCD Code
• BCD – Binary Coded Decimal
Step of conversion
84
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.
• Exp: 87410
8 7 4 (decimal)
9 6
Step 2 : Change decimal number to binary
number.
1001 0110BCD 8421 = 11000002
88
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).
Binary Hex 0 1 2 3 4 5 6 7
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
a) 54 4F 4C 4F 4E 47
b) 48 45 4C 4C 4F
c) 41 50 41 4B 48 41 42 41 52
95
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