chapter 1 number and code systems
TRANSCRIPT
-
8/12/2019 Chapter 1 Number and Code Systems
1/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-1
CHAPTER 1
NUMBER AND CODE SYSTEMS
There are many types of number system is used in our life. The binary number system is
the most important one in digital systems, but several others are also important. Thedecimal system is important because it is universally used to represent quantities outside a
digital system. This means that there will be situations where decimal values must be
converted to binary values before they are entered into the digital system. Likewise, there
will be situations where the binary values at the outputs of a digital system must be
converted to decimal values for presentation to the outside world. Two other number
systems that also important are octal and hexadecimal system.
1.1 Number SystemsThere are 4 types of numbering system used in digital system.
a. Decimal system (N10)0, 1, 2, 3, 4, 5, 6, 7, 8, 9
b. Binary system (N2)0, 1
c. Octal system (N8)0, 1, 2, 3, 4, 5, 6, 7
d. Hexadecimal system (N16)0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 23410
OUTCOMES:
Upon completion of this topic, students should be able to:
1. illustrate the knowledge of digital number systems: decimal, binary, octal andhexadecimal
2. illustrate the knowledge of code systems: BCD 8421 and ASCII code
Basic
number
Base
number
-
8/12/2019 Chapter 1 Number and Code Systems
2/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-2
Table 1: Numbering Systems
Decimal
System
Binary
System
Octal
System
Hexadecimal
System
0 0000 0 0
1 0001 1 1
2 0010 2 23 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D14 1110 16 E
15 1111 17 F
Binary Number System:
System Digits: 0 and 1
Bit (short for binary digit): A single binary digit
LSB (least significant bit): The rightmost bit
MSB (most significant bit): The leftmost bit
1.2 Conversion Number Systems1.2.1 Decimal to Binary Conversions
The decimal number will divide by 2 until obtain minimum values. If the decimal
number have the decimal point, so each the decimal point value must be multiply by 2.
Example:
Convert 12310to it binary equivalent.
Ans: 2 123 remainder of 1
2 61 remainder of 12 30 remainder of 0
2 15 remainder of 1
2 7 remainder of 1
2 3 remainder of 1
1
12310= 1 1 1 1 0 1 12MSB LSB
-
8/12/2019 Chapter 1 Number and Code Systems
3/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-3
Example:
Convert 97.5410to it binary equivalent.
Ans: 2 97 - 1 0.54 x 2 = 1 .08
2 48 - 0 0.08 x 2 = 0 .16
2 24 - 0 0.16 x 2 = 0 .32
2 12 - 0 0.32 x 2 = 0 .64
2 6 - 0
2 3 - 1
1
12310= 1 1 0 0 0 0 1.12
1.2.2
Decimal to Octal ConversionsThe decimal number will divide by 8 until minimum values. If the decimal number
have the decimal point, so each the decimal point value must be multiply by 8.
Example:
Convert 39610to it octal equivalent.
Ans: 8 396 remainder of 4
8 49 remainder of 1
6
39610= 6 1 48MSD LSD
Example:
Convert 172.3110to it octal equivalent.
Ans: 8 172 - 4 0.31 x 8 = 2 .48
8 21 - 5 0.48 x 8 = 3 .84
2 0.84 x 8 = 6 .72
0.72 x 8 = 5 . 76
172.3110= 254.23658
-
8/12/2019 Chapter 1 Number and Code Systems
4/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-4
1.2.3 Decimal to Hexadecimal ConversionsThe decimal number will divide by 16 until minimum values. If the decimal number
have the decimal point, so each the decimal point value must be multiply by 16.
Example:
Convert 698310to it hexadecimal equivalent.
Ans: 16 6983 remainder of 7
16 436 remainder of 4
16 27 remainder of 11
1
698310= 1 B 4 716MSD LSD
Example:
Convert 5932.7610to it binary equivalent.
Ans: 16 5932 - 12 0.76 x 16 = 12 .16
16 370 - 2 0.16 x 16 = 2 .56
16 23 - 14 0.56 x 16 = 8 .96
1 0.96 x 16 = 15 .36
5932.7610= 1 E 2 C . C 2 8 F16
1.2.4 Binary to Decimal Conversions
Example :
Convert 1012to it decimal equivalent.
Ans: 1012 = (1 x 22) + (0 x 21) + (1 x 20)
= (1 x 4) + (0 x 2) + (1 x 1)
= 4 + 0 + 1
= 510
Binary System
.25 24 23 22 21 20 2-1 2-2 2-3..
.32 16 8 4 2 1 0.5 0.25 0.125.
-
8/12/2019 Chapter 1 Number and Code Systems
5/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-5
Example :
Convert 1011.012to it decimal equivalent.
Ans: 1011.0112 = (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) + (1 x 2-3)
= (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1) + (0 x 0.5) + (1 x 0.25) + (1 x 0.125)
= 8 + 0 + 2 + 1 + 0 + 0.25 + 0.125
= 11.37510
1.2.5 Octal to Decimal Conversions
Example :
Convert 6258to it decimal equivalent.
Ans: 6258 = (6 x 82) + (2 x 81) + (5 x 80)
= (6 x 64) + (2 x 8) + (5 x 1)
= 384 + 16 + 5
= 40510
Example :
Convert 31.78to it decimal equivalent.
Ans: 31.78 = (3 x 81) + (1 x 80) + (7 x 8-1)
= (3 x 8) + (1 x 1) + (7 x 0.125)
= 24 + 1 + 0.875
= 25.87510
1.2.6 Hexadecimal to Decimal Conversions
Example :
Convert 1D216to it decimal equivalent.
Ans: 1D216 = (1 x 162) + (D x 161) + (2 x 160)
= (1 x 256) + (13 x 16) + (2 x 1)
= 256 + 208 + 2
= 46610
Octal System
.....83 82 81 80 8-1 8-2..
512 64 8 1 0.125 0.015625.
Hexadecimal System
.....163 162 161 160 16-1 16-2..
4096 256 16 1 0.0625 0.0039.
-
8/12/2019 Chapter 1 Number and Code Systems
6/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-6
Example :
Convert A69.5C16to it decimal equivalent.
ANS: A69.5C16 = (A x 162) + (6 x 161) + (9 x 160) + (5 x 16-1) + (C x 16-2)
= (10 x 256) + (6 x 16) + (9 x 1) + (5 x 0.0625) + (12 x 0.0039)
= 2560 + 96 + 9 + 0.3125 + 0.0468
= 2665.359310
1.2.7 Binary to Octal ConversionsAssign the each bit binary numbers into 3 bit from LSB to MSB. It is because octal
value need 3 bit of binary value to complete the systems.
Example :
Convert 110101002to it octal equivalent.
Ans:
110101002=3248
Example :
Convert 10110.01012to it octal equivalent.
Ans:
10110.01012=26.248
Binary
System
Octal
System
000 0001 1
010 2
011 3
100 4
101 5
110 6
111 7
MSB LSB
0 1 1 0 1 0 1 0 0
3 2 4
0 1 0 1 1 0 0 1 0 1 0 0
2 6 2 4
-
8/12/2019 Chapter 1 Number and Code Systems
7/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-7
1.2.8 Binary to Hexadecimal ConversionsAssign the each bit binary numbers into 4 bit from LSB to MSB. It is because
hexadecimal value need 4 bit of binary value to complete the systems.
Example :
Convert 10110110102to it hexadecimal equivalent.
Ans:
10110110102=2DA16
Example :
Convert 11110001.0101112to it hexadecimal equivalent.
Ans:
11110001.0101112 =F1.5C16
Binary
System
Hexadecimal
System0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
MSB LSB
0 0 1 0 1 1 0 1 1 0 1 0
2 D A
1 1 1 1 0 0 0 1 0 1 0 1 1 1 0 0
F 1 5 C
-
8/12/2019 Chapter 1 Number and Code Systems
8/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-8
1.2.9 Hexadecimal to Binary ConversionsExample:
Convert 195D16to it binary equivalent.
Ans:
195D16 = 11001010111012
Example :
Convert 8E2.A616to it binary equivalent.
Ans:
8E2.A616 =100011100010.10100112
1.2.10Hexadecimal to Octal ConversionsThere are two methods to convert the hexadecimal to octal systems. The methods
are:
1. HexadecimalBinaryOctal2. HexadecimalDecimalOctal
Example:
Convert 62E316to it octal equivalent.
ANS:
Method 1: Hexadecimal Binary Octal
62E316 = 613438
Method 2: Hexadecimal Decimal Octal
Hexadecimal Decimal :62E316= (6 x 163) + (2 x 162) + (14 x 161) + (3 x 160)
= (6 x 4096) + (2 x 256) + (14 x 16) + (3 x 1)
= 24576 + 512 + 224 + 3
= 2531510
1 9 5 D0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 1
MSB LSB
8 E 2 A 6
1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 0 0 1 1 0
Hexa 6 2 E 3
Binary 0 0 0 1 1 0 0 0 1 0 1 1 1 0 0 0 1 1
Octal 0 6 1 3 4 3
This method is easier and it can reduce calculation careless.
-
8/12/2019 Chapter 1 Number and Code Systems
9/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-9
Decimal Octal : 2531510=613438
62E316 = 613438
Example :
Convert 2C.1916to it octal equivalent.
Ans:
Method 1: Hexadecimal Binary Octal
2C.1916 = 54.0628
Method 2: Hexadecimal Decimal Octal
Hexadecimal Decimal : 2C.1916= (2 x 161) + (12 x 160) + (1 x 16-1) + (9 x 16-2)
= (2 x 16) + (12 x 1) + (1 x 0.0625) + (9 x 0.00391)
= 32 + 12 + 0.0625 + 0.03519
= 44.0976910
Decimal Octal : 0.09769 x 8 = 0 .78152
0.78152 x 8 = 6 .25216
0.25216 x 8 = 2 .01728
So, it will be: 44.0976910=54.0628
2C.1916 = 54.0628
8 25315 - 3
8 3164 - 4
8 395 - 3
8 49 - 1
6
Hexa 2 C 1 9
Binary 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0
Octal 0 5 4 0 6 2
8 44 - 4
5
-
8/12/2019 Chapter 1 Number and Code Systems
10/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-10
1.2.11Octal to Hexadecimal ConversionsThere are two methods to convert the hexadecimal to octal systems. The methods
are:
1. OctalBinaryHexadecimal2. OctalDecimalHexadecimal
Example :
Convert 42578to it hexadecimal equivalent.
Ans:
Method 1: Octal Binary Hexadecimal
42578 = 8AF16
Method 2: Octal Decimal Hexadecimal
Octal Decimal : 42578 = (4 x 83) + (2 x 82) + (5 x 81) + (7 x 80)
= (4 x 512) + (2 x 64) + (5 x 8) + (7 x 1)
= 2048 + 128 + 40 + 7
= 222310
Decimal Hexadecimal:
222310 =8AF16
42578 = 8AF16
Example :
Convert 741.258to it hexadecimal equivalent.
Ans:
Method 1: Octal Binary Hexadecimal
741.258 = 1E1.5416
Octal 4 2 5 7
Binary 1 0 0 0 1 0 1 0 1 1 1 1
Hexa 8 A F
16 2223 - F
16 138 - A
8
Octal 7 4 1 2 5
Binary 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0
Hexa 1 E 1 5 4
This method is easier and it can reduce calculation careless.
-
8/12/2019 Chapter 1 Number and Code Systems
11/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-11
Decimal
Division
Binary
Octal
Hexadecimal
Multiplication
Decimal
REMEMBERCONVERSION NUMBER SYSTEMS
Number system positions
.N5 N4 N3 N2 N1 N0 N-1 N-2 N-3..
Method 2: Octal Decimal Hexadecimal
Octal Decimal : 741.258 = (7 x 82) + (4 x 81) + (1 x 80) + (2 x 8-1) + (5 x 8-2)
= (7 x 64) + (4 x 8) + (1 x 1) + (2 x 0.125) + (5 x 0.015625)
= 448 + 32 + 1 + 0.25 + 0.078125
= 481.3281210
Decimal Hexadecimal:
0.32812 x 16 = 5 .24992
0.24992 x 16 = 3 .99872
0.99872 x 16 = F .97952
481.3281210=1E1.53F16
741.258 = 1E1.53F16
16 481 - 1
16 30 - E
1
Binary
Octal
Hexadecimal
Multiply
Decimal
Division Binary
Octal
Hexadecimal
Note: For decimalvalue must be multiply
by their base
-
8/12/2019 Chapter 1 Number and Code Systems
12/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-12
1.3 Arithmetic of Number Systems1.3.1 Binary Arithmetic1.3.1.1 Addition
Note: The rules of binary addition (without carries) are the same as the truths of the
XORgate.
Example :
1. 10102+ 1112= 100012
2. 111102+ 100112= 1100012
1.3.1.2 Subtraction
Example :
1. 1010121102= 11112
1 0 1 02 = 1010
+ 1 1 12 = 710
1 0 0 012 = 1710
1 1 1 1 02 = 3010
+ 1 0 0 1 12 = 19101 1 0 0 0 12 = 4910
1 0 1 0 12 = 2110
- 1 1 02 = 610
1 1 1 12 = 1510
0
Rules of Binary Addition:0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0 and carry 1 to the next more significant bit
Rules of Binary Subtraction:
0 - 0 = 0
0 - 1 = 1 and borrow 1 from the next more significant
1 - 0 = 1
1 - 1 = 0
11
12+ 12= 102
110+ 110= 210
111
100101 10
http://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gateshttp://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gateshttp://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gates -
8/12/2019 Chapter 1 Number and Code Systems
13/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-13
1.3.1.3 Multiplication
Note: The rules of binary multiplication are the same as the truths of theANDgate.
Example :
1. 1012 112= 11112
1.3.1.4 DivisionBinary division is the repeated process of subtraction, just as in decimal division.
Example:
1. 1010102 1102= 1112 1 1 11 1 01 0 1 0 1 0
- 1 1 0
1 0 0 1
- 1 1 01 1 0
1 1 0
1 0 1 = 510
1 1 = 310
1 0 1 1510
+ 1 0 1
1 1 1 1
Rules of Binary Multiplication:
0 0 = 0
0 1 = 0
1 0 = 01 1 = 1 and no carry or borrow bits
. . .
http://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gateshttp://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gateshttp://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gateshttp://academic.evergreen.edu/projects/biophysics/technotes/program/logic.htm#gates -
8/12/2019 Chapter 1 Number and Code Systems
14/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-14
2. 100001112 1012= 1101121 1 0 1 1
1 0 11 0 0 0 0 1 1 1- 1 0 1
1 1 0
- 1 0 11 1
- 01 1 1
- 1 0 11 0 1
- 1 0 1
1.3.2 Octal Arithmetic1.3.2.1 Addition
Example:
1. 6538+ 1228=7758
2. 7168+ 1548=7758
1.3.2.2 Subtraction
Example:
1. 13648- 1238=12418
6 5 38
+ 1 2 28
7 7 58
7 1 68
+ 1 5 48
1 0 7 28
1 3 6 48
- 1 2 38
1 2 4 18
. . .
6 + 4 = 10 8= 2
7 + 1 = 8 8= 0
11
-
8/12/2019 Chapter 1 Number and Code Systems
15/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-15
2. 36458- 7518=26748
1.3.3 Hexadecimal Arithmetic1.3.3.1 Addition
Example:
1. 952116+ 1A616=96C716
2. 3F216+ 6E16=46016
1.3.3.2 Subtraction
Example:
1. 2B991639816=280116
2. 6EF316FF16=6DF48
3 6 4 58
- 7 5 18
2 6 7 48
9 5 2 116
+ 1 A 616
9 6 C 716
3 F 216
+ 6 E16
4 6 016
2 B 9 916
- 3 9 816
2 8 0 116
6 E F 316
- F F16
6 D F 416
4 +8= 12 5 = 7
5 + 8= 13 7 = 6
58
2 8
2 + 14 = 16 16= 0
15 + 1 + 6 = 22 16= 6
11
16 +3 = 19 15 = 4
16 + 14 = 30 - 15 = F
D E 1616
-
8/12/2019 Chapter 1 Number and Code Systems
16/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-16
1.4 Sign NumbersIn digital systems, the binary numbers are represented by a set of binary such as a
microprocessor register 8 bits. The most significant bit (MSB) is the sign bit. If this
bit is 0, then the number is (+) positive. However, if the sign bit is 1, then the
number is (-) negative. The other 7 bits in this 8-bit register represent the
magnitude of the number.
Sign bit 0 = (+)
1 = ()
MSB LSB
Magnitude
Figure below :Representation of signed numbers in sign-magnitude form.
A7 A6 A5 A4 A3 A2 A1 A0
0 0 1 0 1 1 0 1 = +4510
Sign
bit
(+)
True binary
A7 A6 A5 A4 A3 A2 A1 A0
1 1 1 0 1 0 1 1 = -4510
Sign
bit
(-)
2s complement
1.5 2s Complement NumbersThe 2s complement method of representing numbers is widely used inmicroprocessor based equipment. Until now, we have assumed that all numbers are
positive. However, microprocessors must process both positive and negative
numbers. By using 2s complement representation, the sign as well as the magnitudeof a number can be determined.
1s Complement
The 1s complement of a binary number is obtained by changing each 0 to a 1 andeach 1 to a 0. In other words, change each bit in the number to its complement.
Example:
Original binary number 0 0 1 0 1 1 0 1
1s complement 1 1 0 1 0 0 1 0
-
8/12/2019 Chapter 1 Number and Code Systems
17/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-17
2s Complement
The 2s complement of a binary number is formed by taking the 1s complement ofthe number and adding 1 to the least-significant-bit position.
Example:
Original binary number 0 0 1 0 1 1 0 1
1s complement 1 1 0 1 0 0 1 0
Add 1 to form 2s complement + 12s complement of original number 1 1 0 1 0 0 1 1
Example:
Represent the signed decimal numbers below as a signed binary number in 2scomplement system. Use a total of five bits including the sign bit.
a) + 13b) 9
Ans:
a) + 13 = 01101
sign bit
b) + 9change to 9 by using 2s complement
9 = 10111
1.5.1 Arithmetic of 2s ComplementCase I: Two Positive Numbers
The addition of two positive numbers is straight forward.
Example: + 9 + 4 = + 13
+ 9 0 1001+ 4 + 0 0100
0 1101
sign bits
+ 9 010011s complement 10110
Add 1 + 1
2s complement 10111
-
8/12/2019 Chapter 1 Number and Code Systems
18/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-18
Case II: Positive Number and Smaller Negative Number
Consider the addition of +9 and 4. Remember that the 4 will be in its 2scomplement form. Thus, +4 (00100) must be converted to 4 (11100).
Example: + 9 4 = + 5sign bits
+ 9 0 1001- 4 + 1 1100
1 0 0101
This carry is disregarded; the result is 00101 (sum = +5)
Case III: Positive Number and Larger Negative Number
Consider the addition of 9 and + 4.
Example: - 9 + 4 = - 5
- 9 1 0111+ 4 + 0 0100
1 1011 (sum = - 5)
negative sign bits
Case IV: Two Negative Numbers
Consider the addition of 9 and 4.
Example: - 9 4 = - 13sign bits
- 9 1 0111- 4 + 1 1100
1 1 0011
This carry is disregarded; the result is 10011 (sum = - 13)
Case V: Equal and Opposite Numbers
Example: - 9 + 9 = + 0
sign bits
- 9 1 0111+ 9 + 0 1001
1 0 0000
This carry is disregarded; the result is 00000 (sum = + 0)
-
8/12/2019 Chapter 1 Number and Code Systems
19/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-19
1.5.2 Arithmetic OverflowExample:
incorrect sign bits
+ 9 0 1001+ 8 + 0 1000
1 0001
The answer has a negative sign bit, which is obviously incorrect since we are adding
two positive numbers. The answer should be +17, but the magnitude 17 requires
more than four bits and therefore overflows into the sign-bit position. This overflow
condition can occur only when two positive or two negative numbers are being
added, and it always produces an incorrect result. Overflow can be detected by
checking to see that the sign bit of the result is the same as the sign bits of the
numbers being added.
1.6 Code System1.6.1 BCD 8421
Decimal BCD 8421
8 4 2 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 14 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
Example 1:
Convert the following decimal value to BCD code.
a) 593110b) 28.9410
Ans:
a) 593110= 101100100110001BCDDecimal 5 9 3 1
BCD code 0 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1
-
8/12/2019 Chapter 1 Number and Code Systems
20/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-20
b) 28.9410= 101000.100101BCD
Example 2:
Convert the following BCD code to it decimal value equivalent.
a) 10101010101000101BCDb) 101001100.1001011BCD
Ans:
a) 10101010101000101BCD= 1554510
b) 101000011.1001011BCD= 143.9610
1.6.1.1 Arithmetic of BCD code
BCD addition follows the same rules asbinary addition.However, if the addition
produces a carry and/or creates an invalid BCD number, an adjustment is required
to correct the sum. The correction method is to add 6 to the sum in any digit
position that has caused an error.
Case I: Sum Equals 9 or Less
Example:
1.
2.
Decimal 2 8 9 4
BCD code 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0
Decimal 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1
BCD code 1 5 5 4 5
Decimal 0 0 0 1 0 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0
BCD code 1 4 3 9 6
5 0101BCD
+ 4 + 0100BCD
9 1001BCD
45 0100 0101BCD
+ 33 + 0011 0011BCD
78 0111 1000BCD
http://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#addhttp://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#addhttp://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#add -
8/12/2019 Chapter 1 Number and Code Systems
21/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-21
3.
Case II: Sum Greater Than 9
Example:
1.
2.
1
3.
BCD subtraction follows the same rules asbinary subtraction.However, if the
subtraction causes a borrow and/or creates an invalid BCD number, an adjustment
is required to correct the answer. The correction method is to subtract 6from the
difference in any digit position that has caused an error.
25 0010 0101BCD
+ 12 + 0001 0010BCD
37 0011 0111BCD
6 0110BCD
+ 7 + 0111BCD
13 1101BCD invalid code group for BCD+ 0110BCD add 6 for correction
0001 0011BCD
1 3
47 0100 0111BCD
+ 35 + 0011 0101BCD
82 0111 1100BCD invalid sum in first digit+ 1 0110BCD add 6 for correction
1000 0010BCD correct BCD sum8 2
59 0101 1001BCD
+ 38 + 0011 1000BCD
97 1001 0001BCD invalid sum in first digit+ 0110BCD add 6 for correction
1001 0111BCD correct BCD sum
9 7
1
http://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#subtracthttp://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#subtracthttp://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#subtracthttp://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#subtract -
8/12/2019 Chapter 1 Number and Code Systems
22/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Prepared by: WAN HAMIDAH BINTI WAN ABAS [PKK\JKE]_version01_Dis2012 Page 1-22
1.6.2 ASCII CodeASCII code is used to transmit the digital data through telephone line. Table 1 shown
the sequential of ASCII code table that have alphabets, numbers and some symbols.
ASCII code has 7 bit code. For example, if the data was transmitted is 100 0001, that
means the data is A. So, 100 0001 = A.
Table 1: ASCII code
How to determine the ASCII code:
Example 1:
Y = 59 (hexadecimal)
Y = 101 1001 (binary)
-
8/12/2019 Chapter 1 Number and Code Systems
23/23
EE202 [DIGITAL ELECTRONIC]NUMBER AND CODE SYSTEMS
Example 2:
The following is a message encoded in ASCII code. What is the message?
1001000 10001010 1001100 1010000
Ans:
4 8 4 5 4 C 5 0
1 0 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 1 0 0 1 0 1 0 0 0 0
H E L P