Professional Documents
Culture Documents
Number Systems and Codes: at The End of The Lesson, Students Should Be Able To
Number Systems and Codes: at The End of The Lesson, Students Should Be Able To
2.1
It is expressed as a base of 2.
Weight
Binary
Number
24
23
22
21
20
2-1
2-2
2-3
2-4
MSB
2.2
LSB
Example:
Convert 1210 to binary form.
Solution:
2
12
Remain
0
From below
1210 = 1 1 0 0
1210 = 11002
Check:
Weight
23
22
21
20
Binary Number
= 23 + 22 = 8 + 4 = 12
14
Example 1:
Convert 0.312510 to binary form.
Solution:
Carry
0.3125 2
= 0.625
0.625
= 1.25
0.25
= 0.50
0.5
= 1.00
=0.0101
Example 2:
Convert 0.634210 to binary form.
Solution:
Carry
0.6342
= 1.2684
0.2684
= 0.5368
0.5368
= 1.0736
0.0736
= 0.1472
= . 1010
15
Multiply each bit by positional weight and add the weight of all bits that are
1
Example:
Express 11011012 to decimal form.
Solution:
Weight
26
25
24
23
22
21
20
Binary Number
11011012 = 26 + 25 + 23 + 22 + 21 = 64 + 32 + 8 + 4 + 1 = 109
Example:
1. Convert 0.1011 to decimal point.
Solution:
Weight
20
2-1
2-2
2-3
2-4
Binary Number
0.
0.10112
= 0.6875
16
Solution:
Weight
20
2-1
2-2
2-3
2-4
2-5
Binary Number
0.
0.110012
2.3
Basic rules:
Carry
0+0=0
0+1=1
1+0=1
1+1=0
1 + 1 + (carry) =
1
Example:
1. Add 1012 to 102.
Check:
1
+
1
5
+
2
7
17
Check:
10
+
1
3
13
Check:
13
1
+
1
6
19
Case 1:
1
1
Check:
13
-
4
9
Case 2:
Check:
1
-
10
9
-
4
5
18
Case 3:
10
Check:
33
2.4
10
23
1s and 2s compliment of binary numbers are important because they permit the
representation of negative (-ve) numbers.
1S COMPLEMENTS
0 0 1 0
11012 = 00102
19
2S COMPLEMENTS
Example 1:
Find the 2s complement of 11012.
Solution:
1
Binary number
1s complement
1
0
2s complement
Example 2:
Find the 2s complement of 10011012.
Solution:
1
Binary number
1s complement
Add 1
2s complement
+
0
20
2.5
The left most bit in a signed binary number is the sign bit, which tells you
whether the number is positive or negative.
The magnitude bits are in true (un-complemented) binary for both positive
and negative numbers.
Magnitude bit
REMEMBER:
The MSB is the sign bit, which tells us
weather the number is positive or negative.
Sign bit 0
positive
Sign bit 1
negative
21
1S COMPLEMENT
Example:
Using 8 bits, express decimal number +25 in 1s compliment.
+25
: 0001 1001
binary number
1110 0110
1s complement
2S COMPLEMENT
Example:
Express decimal number -25 as 2s complement.
1s complement
Add 1
2s complement
+
1
22
Example:
Express the decimal number -39 as an 8 bit number in the sign-magnitude,
1s complement and 2s complement forms.
+ 39 = 0010 01112
In the sign-magnitude form -39 = 1010 01112
In 1s complement form -39 :0 0 1 0
0 1 1 1
1 1 0 1
1 0 0 0
1s complement
In 2s complementform -39 :0 0 1 0
0 1 1 1
1 1 0 1
1 0 0 0
1s complement
+
1 1 0 1
2.6
Add 1
1
1 0 0 1
2s complement (-39)
Case 1 :
(+ 7)
+ 0 0 0 0 0 1 0 0
(+ 4)
0 0 0 0 1 0 1 1
(+ 11)
23
Case 2 :
Complement
0 0 0 0
0 1 1 0
1 1 1 1
1 0 0 1
1s complement
1
1 1 1 1
1 0 1 0
Add 1
2s complement (-6)
0 0 0 0 1 1 1 1
(+ 15)
+ 1 1 1 1 1 0 1 0
(- 6)
1 0 0 0 0 1 0 0 1
(+ 9)
Case 3 :
1 0 0 0
1 1 1 0
0 1 1 1
1s complement
1
1 1 1 0
1 0 0 0
Add 1
2s complement (-24)
0 0 0 1 0 0 0 0
(+ 16)
+ 1 1 1 0 1 0 0 0
(- 24)
1 1 1 1 1 0 0 0
(- 8)
24
Case 4 :
- 5 :0 0 0 0
0 1 0 1 (+5)
0 0 0 0
1 0 0 1 (+9)
1 1 1 1
1 0 1 0
1 1 1 1
0 1 1 0
1
1 0 1 1 (-5)
1 1 1 1
1
1 1 1 1
0 1 1 1 (-9)
1 1 1 1 1 0 1 1
(- 5)
+ 1 1 1 1 0 1 1 1
(- 9)
1 1 1 1 1 0 0 1 0
( - 14)
1 1 1 0 1 1 1 1
+ 0 0 0 1 0 0 0 1
+ 9
1 0 0 0 0 0 0 0 0
25
Procedure:
i.
ii.
Add the negation to the minuend the result will represent the
difference between the subtrahend and minuend.
iii.
Example:
Perform each of the following subtractions of the signed numbers:
a) +8 (+3) = 5
b) 12 (-9) = 21
c) -25 (+19) = -44
d) -120 (-30) = -90
Solutions:
a) +8 (+3) = 5
1
b) 12 (-9) = 21
0 0 0 0 1 0 0 0
0 0 0 0 1 1 0 0
+ 1 1 1 1 1 1 0 1
+ 0 0 0 0 1 0 0 1
1 0 0 0 0 0 1 0 1
0 0 0 1 0 1 0 1
1 1 1 0 0 1 1 1
1 0 0 0 1 0 0 0
+ 1 1 1 0 1 1 0 1
+ 0 0 0 1 1 1 1 0
1 1 1 0 1 0 1 0 0
1 0 1 0 0 1 1 0
26
2.7
Octal number system provides a convenient way to express binary numbers and code.
However, it is used less frequently than hexadecimal in conjunction with computers
and microprocessor to express binary quantities for input and output purposes.
BINARY
000
001
010
011
100
101
110
111
Table 1
Example:
Convert each of the following octal numbers to binary.
b)
a) 138
258
c)
1408
d) 72568
Solution:
b)
a)
1
0 0 1
2 5
3
0 1 1
0 1 0
1 0 1
27
c)
1
0 0 1
1 0 0
0 0 0
0 1 0
1 0 1
1 1 0
Solution:
a) 110 101
28
2.8
BINARY
HEXADECIMAL
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
10
1010
11
1011
12
1100
13
1101
14
1110
15
1111
Table 2
29
Example 1:
Convert the following binary numbers to hexadecimal.
Solutions;
a) 1100 1010 0101 0111
b)
Example 1:
Determine the binary numbers for the following hexadecimal numbers.
a)
10A416
1
0 0 0 1
0 0 0 0
4
1 0 1 0
0 1 0 0
30
b)
CF8E16
C
1 1 0 0
1 1 1 1
E
1 0 0 0
1 1 1 0
c)
974216
9
1 0 0 1
0 1 1 1
2
0 1 0 0
0 0 1 0
Example 1 :
Convert 4428910 to hexadecimal numbers.
Solution:
Remain
16
44289
16
2768
16
173
13 = D
16
10
10 = A
4428910 = A D 0 1
0
4428910 = AD0116
31
Example 1:
Convert 0.678510 to hexadecimal numbers.
Carry
0.6785
16
= 0.856
10
0.856
16
= 0.696
13
0.696
16
= 0.136
11
0.136
16
= 0.176
. A D B2
0.678510 = 0.ADB2
Example :
Convert A5C1.0116 to decimal numbers.
Solutions:
Weight
163
162
161
160
16-1
16-2
Hex Number
1.
REMEMBER:
For hexadecimal system, if remainder
larger than 9, replace as follow:
10 = A
13 = D
11 = B
14 = E
12= C
15 = F
32
Example:
Convert 74218 to hexadecimal number.
Solution:
Octal Number
Result
in
Step 4: Convert
74218 = F1116
33
Solution:
Hex Number
Step 1: Expand
each
octal
digits to four
binary bit
1 1 1 0
Step 2: Result
in binary
Step 3: Group
in three
Step
Convert
4:
0 1 1 0
0 1 0 0
1 0 1 1
1 1 1 0 0 1 1 0 0 1 0 0 1 0 1 1
1 1 0
0 1 1
0 0 1
0 0 1
0 1 1
1 6 3 1 1 3
E64B16 = 1631138
34
2.9
BCD is a way to express each of the decimal digits with a binary code.
BCD means that each decimal digit 0 through 9 is represented by a binary code
of four bits.
There are only ten code groups in the DCB system.
To express any decimal number in BCD, replace each decimal digit with the
appropriate 4-bit code.
DECIMAL
DIGIT
0
1
2
3
0000
0001
0010
0011
4
5
6
7
8
9
0100
0101
0110
0111
1000
1001
BCD
Table 3
Example :
Convert each of the following numbers to BCD.
a) 35
b)
98
c)
170
d)
2469
Solutions:
a)
3
0
5
0
35 = 0011 0101BCD
Fatma Syazana Zaini,
IKM Besut, 2010
35
b)
9
1
98 = 1001 1000BCD
c)
1
0
7
1
0
1
d)
2
0
4
0
Example :
Convert each of the following BCD to decimal.
a) 1000 0110
b)
Solutions:
a) 1000 0110
36
2.10
BCD is a numerical code and can be used in arithmetic operation. Addition is the
most important operation because the other three operations (subtraction,
multiplication and division) can be accomplished by the use of addition.
Add the two BCD number using rules for binary addition.
Step 2:
Step 3:
Example 1 :
Add the following BCD numbers:
a. 0011 + 0100
0 0 1 1
0 1 0 0
0 1 1 1
0 0 1 0
0 0 0 1
0 0 1 1
0 0 1 1
0 1 0 1
1 0 0 0
37
1 0 0 0
0 0 0 1
1 0 0 1
0 1 1 0
0 0 1 1
1 0 0 1
0 1 0 0
0 1 0 0
1 0 0 0
0 1 0 1
0 0 0 1
0 1 1 0
0 0 0 0
0 1 1 1
0 1 1 1
Example 2:
Add the following BCD numbers:
a. 1001 + 0100
+
+
0
1
0
1
0
0
0
1
1
1
0
0
0
0
1
1
1
0
1
0
1
b. 1001 + 1001
+
1
+
0 0 0 1
1
1
1
0
0
1
0
0
0
1
0
0
0
1
1
0
1
1
0
0
0
38
0 0 0 1
+ 0 0 0 1
0 1 1 0
0 1 0 1
0 0 1 0
1 0 1 1
0 0 1 1
0 1 1 0
0 0 0 1
0 1 1 0
0 1 0 1
0 1 1 1
0 0 1 1
1 0 1 1
1 0 1 0
0 1 1 0
0 1 1 0
0 0 0 1
0 0 1 0
0 0 0 0
Both
groups
are
invalid (>9)
Add 0110 (6) to both
group
39
2.11
There are many specialized codes used in digital systems. Some codes are
strictly numeric like BCD and others are alphanumeric that is they used to
represent numbers, letters, symbols and instructions. The code introduced in
this topic is the Gray code.
The Gray Code is un-weighted and is not an arithmetic code: that is there are
no specific weights assigned to the bit positions. The important feature of the
Gray code is that it exhibits only a single bit change from one code word to
the next in sequence.
Table 4 is a listing of the 4-bit Gray code for decimal numbers 0 through 15.
Binary numbers are shown in the table 4 for reference.
DECIMAL
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
BINARY
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
GRAY CODE
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000
Table 4
Fatma Syazana Zaini,
IKM Besut, 2010
40
The most significant bit (left-most) is the Gray code is the same as the
corresponding MSB in the binary number.
ii.
Going from left to right, add each adjacent pair of binary code bits to get the
next Gray code bit. Discard carries.
Example 1:
Convert the binary number 10110 to Gray code.
Binary
Gray
Example 2:
Convert the binary number 1100 0110 to Gray code
1 + 1 + 0 + 0 + 0 + 1 + 1 + 0 Binary
1
1 Gray
The most significant bit (left-most) in the binary code is the same as the
corresponding bit in the Gray code.
ii.
Add each binary code bit generated to the Gray code bit in the next adjacent
position. Discard carries.
41
Example1:
Convert the Gray code below to binary.
a. 11011
b. 1011 1111
ASCII CODES
ASCII has 128 characters and symbols represented by a 7-bit binary code.
Actually ASCII can be considered an 8-bit code with the MSB always 0. This
8-bit code is 00 through 7F in hexadecimal.
The first thirty-two ASCII characters are non-graphic commands that are
never printed or displayed and are used only for control purposes.
Examples of the control characters are null, line feed, start of text and
escape. The other characters are graphic symbols that can be printed or
displayed and include the letters of the alphabet (lowercase and uppercase),
the ten decimal digits, punctuation signs and other commonly used symbols.
42
Table 5 is a listing of the ASCII code showing the decimal, hexadecimal and
binary representations for each character and symbol. The left section of the
table lists the names of the 32-control character (00 through 1F
hexadecimal).
Table 5
The first thirty-two codes in the ASCII table represent the control
characters. These are used to allow devices such as a computer and printer to
communicate with each other when passing information and data.
Table 2 lists the control characters and the control key function that allows
them to be entered directly from an ASCII keyboard by pressing the control
key (CTRL) and the corresponding symbol.
43
Example 1:
Determine the binary ASCII codes that are entered from the computers keyboard
when the following BASIC program statement is typed in also express each code in
hexadecimal.
20 PRINT A= ; X
Solution;
The ASCII code for each symbol is found in table 1.
Symbol
2
0
Space
P
R
I
N
T
Space
A
=
;
X
Binary
011 0010
011 0000
010 0000
101 0000
101 0010
100 1001
100 1110
101 0100
010 0000
010 0010
100 0001
011 1101
010 0010
011 1011
101 1000
Hexadecimal
3216
3016
2016
5016
5216
4916
4E16
5416
2016
2216
4116
3D16
2216
3B16
5816
44
45
SUMMARY
In this topic, students have learned the numeric quantities occur naturally in analogue but
must be converted to digital form to be used by computers or digital circuitry.
Student must understand that the binary numbering system is used in digital systems
because the 1s and 0s are easily represented by ON or OFF transistors, which output
0volt for zero(0) and 5volt for one(1).
Students also must know that the ASCII is used by computers to represent all letters,
numbers and symbols in digital form.
EXERCISE
1. Convert each decimal number to binary.
a. 23
b. 57
c. 45
2. Convert the following binary to decimal
a. 101102
b. 1101 10112
c. 110 11112
d. 1001 11012
3. Determine the 1s complement of each binary number:
a. 0001 1010
b. 1111 0111
c. 1000 1101
4. Determine the 2s complement of each binary number:
a. 0001 0110
b. 1111 1100
c. 1001 0001
Fatma Syazana Zaini,
IKM Besut, 2010
46
5. Using
a.
b.
c.
6. Using
a.
b.
c.
47
14. What is the ASCII representation for each of the following characters?
Express each as a bit and in hexadecimal notation.
a. K
b. r
c. $
d. +
REFERENCES
1. Digital System Principle And Applications, Tocci, R.J, Prentice Hall international
2. Digital Fundamentals, Floyd T.L, Merrill Publishing
3. BPL(K) Module TFV 2033 Digital Electronics 1
4. Digital Electronics: Teaching Module, KUITHO
48