Beruflich Dokumente
Kultur Dokumente
Chapter 2:
DATA REPRESENTATION
IN COMPUTER MEMORY
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).
hexadecimal number.
2.1.2 Perform arithmetic operation (addition
and subtraction) in different number
bases.
2.1.3 Convert decimal, binary, octal and
hexadecimal numbers to different bases and
vice-versa
INTRODUCTION
DECIMAL NUMBERING
SYSTEM
Base number = 10
Basic number = 0,1,2,3,4,5,6,7,8,9
Basic number
23410
Base number
102
101
100
10-1
MSD
LSD
BINARY NUMBERING
Define Binary numbers
SYSTEM
0+0=0
0+1=1
1+0=1
1 + 1 = 10
1 + 1 + 1 = 11
Exercise
Ex 1:
110112 + 100012 = 1011002
Ex 2:
101112 + 1112 = ________
Subtraction
Four conditions in binary subtraction
0 - 0 = 0
0 - 1 = 1 borrow 1
1 - 0 = 1
1 - 1 = 0
10 - 1 = 1
If a 10 being borrow a 1, whats left with
that 10 is a 1
Ex 1:
10012 102 = 1112
Ex 2:
1010112 11112 =__________
Conversions of Binary
Numbers
Binary to Decimal conversions
Example : 1
1
0
1
1
24 + 23 + 22 + 21 + 20 = 16 + 8 + 2 + 1
= 2710
OCTAL NUMBERING
SYSTEM
The octal number system has a base of eight,
83
82
81
80
8-1
8-2
8-3
Ex:
5248 1678 = 3358
1678 248 = _________
Ex:
Ex:
1238
4578
+ 3218
+ 2458
4448
Decimal-to-Octal Conversion
HEXADECIMAL NUMBERING
SYSTEM
Basic number
7A16
Base number
Hexadecimal number -
Addition (Penambahan)
Ex:
3 316
4 716
7 A16
Ex:
2 0 D 316
+ 1 2 B C16
Hexadecimal number -
Subtraction (Pengurangan)
Ex:
4 416
1 716
2 D16
Ex:
3 2 5 516
- 3 1 8 216
Hexadecimal-To-Decimal
Conversion
Ex 1:
1416 = (1 x 161) + (4 x 160)
= 16 + 4
= 2010
Ex 2:
ABC16 = (10 x 162) + (11 x 161)
= (12 x 160)
= 2560 + 176 + 12
= 274810
Decimal-To-Hexadecimal
Conversion
16
20
16
4
2010 = 1416
Hexadecimal-to-Binary
Conversion
Ex:
111010012 = __________
00101101001111002 =___________
Binary-to-Hexadecimal
Conversion
Summary
Hexadecimal
0
1
2
3
4
5
6
7
Decimal
0
1
2
3
4
5
6
7
Binary
0000
0001
0010
0011
0100
0101
0110
0111
Summary
Hexadecimal
8
9
A
B
C
D
E
F
Decimal
8
9
10
11
12
13
14
15
Binary
1000
1001
1010
1011
1100
1101
1110
1111
Magnitude =
Size
Or value
Ones Complements
Exp:
Exp:
Twos Complement
Exercise
1.
-101110012
-5768
01000 0001
-124516
-4510
01000 0010
Addition in 1s complement
1000
1100
10100
1
0101
Addition in 2s complement
-3 change to 1s complement
-3 change to 2s complement
8 change to binary number
This carry is disregarded, the result is 0101 (sum=5)
0111
-8 change to 1s complement
1
1000
0011
1011
-8 change to 2s complement
3 change to binary number
negative sign bit
Subtraction in 1s
complement
1310 = 11012
+
+
11001
10010
101011
1
01100
Subtraction in 2s
complement
Change the number are given to binary
number.
1310 = 11012
25 change to binary
-13 change to 2s complement
total=12
Carry disregard
Exercise
i.
ii.
101110 - 56910
Signed Number
Exp 1:
(-4) + (+8) = +4
-4
11111100
+ (+8)
00001000
+4
1 00000100
00000100
11111011
+4
1s complements
+
1
11111100
2s complements
Exp 1:
(-12) + (+5) = -7
-12
11110100
+ +5
00000101
-7
11111001
00001100
11110011
+12
1s complements
+
1
11110100
2s complements
Exp:
+10 (-5) = +10 + (+5)
= + 15
+10
+ 5
+15
00001010
00000101
00001111
Exp:
-10 (+5) = - 15
- 10
- (+5)
-15
11110110
00000101
11110110
+ 11111011
111110001
Exp:
-10 (-5)
-10
- (- 5)
- 5
= -10 + (5)
=-5
11110110
00000101
11111011
BCD Code
5421
5311
4221
3321
2421
8421
7421
0000
0000
0000
0000
0000
0000
0000
0001
0001
0001
0001
0001
0001
0001
0010
0011
0010
0010
0010
0010
0010
0011
0100
0011
0011
0011
0011
0011
0100
0101
1000
0101
0100
0100
0100
1000
1000
0111
1010
1011
0101
0101
1001
1001
1100
1100
1100
0110
0110
1010
1011
1101
1101
1101
0111
1000
1011
1100
1110
1110
1110
1000
1001
1100
1101
1111
1111
1111
1001
1010
Binary-Coded-Decimal Code
Exp: 87410
8
(decimal)
1000
0111
0100
(BCD)
Exp:
Convert 1001 0110BCD 8421 to binary number.
9
6
Step 2 : Change decimal number to binary
number.
1001 0110BCD 8421 = 11000002
code.
Step 1: Change binary number to decimal
number.
10010102 = 7410
Step 2: Change decimal number to BCD
8421 code.
ASCII Code
ASCII code
MSB
LSB
Binary
000
001
010
011
100
101
110
111
Binary
Hex
0000
Nul
Del
sp
0001
Soh
Dc1
0010
Stx
Dc2
0011
Etx
Dc3
0100
Eot
Dc4
0101
End
Nak
0110
Ack
Syn
&
0111
Bel
Etb
1000
Bs
Can
1001
HT
Em
1010
LF
Sub
1011
VT
Esc
1100
FF
FS
<
1101
CR
GS
1110
SO
RS
>
1111
SI
US
Exp:
An operator is typing in a BASIC program
at the keyboard of a 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
Solution:
Locate each character (including the
space) and record ASCII code.
G
O
T
O
(space)
2
5
01000111
01001111
01010100
01001111
00100000
00110010
00110101
*0wasaddedtotheleftmostbitofeachASCIIcodebecausethe
Codesmustbestoredasbytes(eightbits).
Exercise :
1.The following message encode in ASCII
code. What the meaning of this code ?
a) 54 4F 4C 4F 45 47
b) 48 45 4C 4C 4F
c) 41 50 41 4B 48 41 42 41 52
EBCDIC