Download chapter 1 - UniMAP Portal

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Digital electronics wikipedia , lookup

Manchester Mark 1 wikipedia , lookup

Transcript
DNT 231 - Digital System
CHAPTER 2
Number Systems and Codes
2.0 Introduction
Many numbers systems are use in digital technology. The most common are the decimal,
binary, octal and hexadecimal system.
2.1 Decimal Number
The decimal number composed of 10 symbols. Ex: 0,1,2,3,4,5,6,7,8,9; these symbols as
digits of the numbers. The decimal number also called the base 10 number because it has
ten digits.
Example:
2745.214 = (2 x 103) + (7 x 102) + (4 x 101) + (5 x 100) + (2 x 10-1) + (1 x 10-2) + (4 x 10-3)
or
Positional values
103
2
102
7
101
4
MSB
100
5
.
10-1
2
10-2
1
Decimal Point
10-3
4
LSB
MSB = Most Significant Point
LSB = Least Significant Point
Example:
Express the decimal number 47 as a sum of the values of each digit.
47 = (4 x101) + (7 x 100) = (4 x 10) + (7 x 1) = 40 + 7
Exercise:
What weight does the digit 7 have in each of the following numbers?
a) 1370 b) 6725 c) 7051 d) 58.72
ANS: a) 10 b) 100 c) 1000 d) 0.1
2.2 Binary Number
It is very difficult to design electronic equipment so that it can work with 10 different
voltage levels (each one representing one decimal character, 0 through 9). On the other
hand, it is very easy to design simple, accurate electronic circuits that operate with only
two voltage levels. Almost every digital system uses the binary (base 2) number system
as the basic number system of its operations. In the binary number only have two possible
1
DNT 231 - Digital System
digit values, 0 and 1. Each binary digit has its own value or weight expressed as a power
of 2.
Positional values
23
1
22
0
21
1
20
1
.
2-1
1
2-2
0
2-3
1
In the binary number, the term binary digit is often abbreviated to the term bit.
102
1112
2 bits
3 bits
The left most bit is the MSB and the right most bit is LSB.
The value of a bit is determined by its position in the number. In general, with n bits you
can count up to a number equal to 2n – 1.
For example, with three bits (n = 3), you can count from zero to seven.
Decimal Number
0
1
2
3
4
5
6
7
0
0
0
0
1
1
1
1
Binary
Number
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Example:
Convert the binary whole number 1101101 to decimal.
Weight
Binary Number
1101101
26
1
25
1
24
0
23
1
22
1
21
0
20
1
= (1 x 26) + (1 x 25) + (0 x 24) + (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20)
= 64+ 32 +0 + 8 + 4 +0 + 1
= 109
2
DNT 231 - Digital System
Example:
Convert the fractional binary number 0.1011 to decimal.
2-1
1
Weight
Binary Number
.
2-2
0
2-3
1
2-4
1
= (1 x 2-1) + (0 x 2-2) + (1 x 2-3) + (1 x 2-4)
= 0.5 + 0.125 + 0.0625
= 0.6875
2.2.1 Decimal to Binary Conversion
Two ways to convert a decimal number to decimal number:
1) using sum of weights method
2) using the repeated division by 2
0.1011
2.2.2 Sum of Weights Method
To get the binary number for a given decimal, find the binary weights that add up to the
decimal number.
Binary weight
2N
.
23
.
22
21
20
Placing bit
Example:
Convert the decimal number 1110 to binary using sum of weight method.
23
22
21
20
1
0
1
1
1110 = (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20) = 1011
2.2.3 Repeated Division by 2 Method
Another method for converting decimal integers uses repeated division by 2. It requires
repeatedly dividing the decimal number by 2 and writing down the reminder after each
division until a quotient of 0 is obtained.
3
DNT 231 - Digital System
Example:
Convert the decimal number 1110 to binary using repeated division by method.
11
2
=5
Reminder
1
5
2
=2
1
2
2
=1
0
1
2
=0
1
LSB
MSB
Stop when the whole number quotient is 0
Therefore 1110 = 1011
2.3 Converting decimal fractions to Binary
Two ways to convert a decimal number to decimal number:
1) using sum of weights method
2) using the repeated multiplication by 2
Example: Method 1- Sum of weights method
Convert the decimal number 0.625 to binary using repeated division by method
0.625 = 0.5 + 0.125 = 2-1 + 2-3 = 0.101
0
.
2-1
2-2
2-3
.
1
0
1
Exercise:
1. Convert each decimal number to binary by using the sum of weights method
a) 23 b) 57 c) 45.5
2. Convert each decimal number to binary by using the repeated division by 2
method (repeated multiplication by 2 for faction)
a) 14 b) 21 c) 0.375
ANS: 1a) 10111
2a) 1110
b) 111001
b) 10101
c) 101101.1
c) 0.011
4
DNT 231 - Digital System
2.4 Binary Arithmetic
The four basic rules for adding binary digits (bits) are as follows:
0+0=0
Sum of 0 with a carry of 0
0+1=1
Sum of 1 with a carry of 0
1+0=1
Sum of 1 with a carry of 0
1+1=0
Sum of 0 with a carry of 1
Example:
Carry
Carry
1
1
0
0
1
+
1
0
0
1
1
0
Example:
Add the following binary numbers:
a) 11 + 11
b) 100 + 10 c) 111 + 11
d) 110 + 100
a)
Carry
Carry
1
1
+
1
b)
1
+
1
0
1
1
0
0
0
Check
(4)
(2)
(6)
1
1
0
Check
(7)
(3)
(10)
c)
1
+
1
0
1
1
1
5
1
1
1
1
1
0
DNT 231 - Digital System
d)
+
1
1
1
0
1
0
1
0
0
0
Check
(6)
(4)
(10)
2.4.1 Binary Subtraction
The Four basic rules for subtracting bits are follows:
0–0=0
1–1=0
1–0=1
10 – 1 = 1
0 – 1 with a borrow of 1
Example:
Perform the following binary subtractions:
a) 11 – 01
b) 11 – 10
a)
-
1
0
1
1
1
0
check
(3)
(1)
(2)
1
0
1
check
(3)
(2)
(1)
b)
-
1
1
0
Example:
Subtract 011 from 101
-
1
0
0
0
1
1
1
1
0
Check
(5)
(3)
(2)
2.4.2 Binary Multiplication
The four basic rules for multiplying bits are as follows:
0x0=0
0x1=0
1x0=0
1x1=1
6
DNT 231 - Digital System
Example:
Perform the following binary multiplications:
a) 11 x 11
b) 101 x 111
a)
1
1
1
1
0
x
.
1
1
0
1
1
1
.
1
check
(3)
(3)
(9)
b)
x
+
1
0
1
0
1
0
1
1
1
0
1
0
1
0
1
0
1
1
1
1
check
(7)
(5)
(35)
.
1
2.4.3 Binary Division
Division in binary follows the same procedure as division in decimal.
Example:
Perform the following binary divisions:
a) 110 ÷ 11 b) 110 ÷ 10
a)
10
11 110
11
000
b)
11
10 1 0 0
1 0
1 0
1 0
0 0
7
DNT 231 - Digital System
2.5 1’s and 2’s Complements of Binary Numbers
Finding the 1’s Complement
The 1’s complement of a binary number is found by changing all 1s to 0s and all 0s to 1s.
Example
1
0
1
1
0
0
1
0
Binary Number
0
1
0
0
1
1
0
1
1’s complement
The simplest way to obtain the 1’s complement of a binary number with a digital circuit
is to use parallel inverter (NOT circuits), as shown in Figure 2.1 for an 8 bit binary
number.
Figure 2.1: To obtain the 1’s complement using inverters
Finding the 2’s Complement
The 2’s complement of a binary is found by adding 1 to the LSB of the 1’s complement.
2’s complement = (1’s complement) + 1
Example:
Find the 2’s complement of 10110010.
1
0
0
1
1
0
1
0
0
1
0
1
1
0
0
1
0
0
1
1
1
+
8
0
1
1
0
Binary number
1’s complement
Add 1
2’s complement
DNT 231 - Digital System
Alternative Method:
An alternative method of finding the 2’s complement of a binary number is as follows:
1) Start at the right with the LSB and write the bits as they are up to and including
the first 1.
2) Take the first complements of the remaining bits.
Example:
Find the 2’s complement 0f 10111000 using the alternative method.
1
0
0
1
1
0
1
0
1
1
0
0
1’s complements of original bits
0
0
0
0
Binary number
2’s complement
These bits stay the same
The 2’s complement of a negative binary number can be realized using inverters and an
adder, as indicated in Figure 2.2. An 8 bit number can be converted to its 2’s complement
by first inverting each bit (taking the 1’s complement) and then adding 1 to the 1’s
complement with an adder circuit.
Figure 2.2: To obtain the 2’s complement of a negative binary number
2.6 Hexadecimal Number
The hexadecimal number uses base 16. It has 16 possible digit symbols. It uses the digits
0 through 9 plus A, B, C, D, E, E, and F as the 16 digit symbols. The digit positions are
weighted as powers of 16 as shown below, rather than as powers of 10 as in the decimal
system.
164
163
162
161
160
9
. 16
-1
16-2
16-3
16-4
DNT 231 - Digital System
Table 1 shows the relationships among hexadecimal, decimal, and binary.
Hexadecimal
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
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
2.6.1 Hex to Decimal Conversion
A hex 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. The LSD has a weight of 160 = 1 and the
MSD is 16N.
Example:
Convert the hexadecimal number to decimal number.
a) 35616 = (3 x 162) + (5 x 161) + (6 x 160) = 768 + 80 + 6 = 85410
b) 2AF10 = (2 x 162) + (10 x 161) + (15 x 160) = 512 + 160 + 15 = 68710
2.6.2 Hex to Binary Conversion
Used “shorthand” method for representing binary numbers. Conversion hexadecimal and
binary is direct and easy.
Example:
Determine the binary numbers for the following hexadecimal numbers.
a) 10A416
b) CF8E16
c) 974216
a)
1
0
A
4
0001
0000
1010
0100
10
DNT 231 - Digital System
Therefore 10A416 = 1000010100100
The MSB is understood to have zeros preceding it, thus forming 4 bit group.
b)
C
F
8
E
1100
1111
1000
1110
9
7
4
2
1001
0111
0100
0010
c)
2.6.3 Decimal to Hex Conversion
Decimal to Hex Conversion can be done using repeated division by 16.
Example:
Convert 42310 to hex.
423
16
= 26
Remainder
7
26
16
=1
10
1
16
=0
1
42310 = 1A716
2.6.4 Binary to Hex Conversion
The binary number is grouped into groups of four bits, and each group is converted to its
equivalent hex digit. Zeros are added, as needed, to complete a four bit group.
Example:
Converting the following binary numbers to hexadecimal:
a) 1100101001010111
b) 111111000101101001
11
DNT 231 - Digital System
a)
1100
1010
0101
0111
C
A
5
7
therefore 11001010010101112 = CA5716
b)
0011
1111
0001
0110
1001
F
1
6
9
3
therefore 1111110001011010012 = 3F16916
2.7 Binary Coded Decimal (BCD)
The 8421 code is a type of BCD code. BCD means that each decimal digit, 0 through 9,
represented by a binary coded of four bits. The designation 8421 indicates the binary
weights of the four bits (23, 22, 21, 20).
Invalid Codes – The six code combinations that are not used – 1010, 1011, 1100, 1101,
1110, and 1111
Example:
Convert each of the following decimal number to BCD:
a) 35 b) 98 c) 170 d) 2469
a)
3
5
0011
therefore 3510 = 00110101
b)
9
0101
1001
therefore 9810 = 10011000
1000
8
12
DNT 231 - Digital System
c)
1
7
0
0001
0111
therefore 17010 =000101110000
0000
d)
2
4
6
9
0010
0100
0110
1001
therefore 246910 = 0010010001101001
Example:
Convert each of the following BCD codes to decimal:
a) 10000110 b) 001101010001
c) 1001010001110000
a)
1000
0110
8
6
therefore 10000110 = 8610
b)
0011
0101
0001
3
5
therefore 001101010001 = 35110
1
c)
1001
0100
0111
0000
9
4
7
0
therefore 1001010001110000 = 947010
1.5.1 BCD Addition
BCD is numerical code and can be used in arithmetic operation.
Step:
1) Add the two BCD numbers, using the rules for binary addition
2) If a 4 bit sum is equal to or less than 9, it is a valid BCD number
13
DNT 231 - Digital System
3) If a 4 bit sum is greater than 9, or if a carry out of the 4 bit is generated, it is an
invalid result. Add 6 (0110) to the for bit sum in order to skip the six invalid states
and return the code to 8421. If a carry results when 6 is added, simply add the
carry to the next 4 bit group.
Example:
Add the following BCD numbers:
a) 0011 + 0100
c) 10000110 + 00010011
b) 00100011 + 00010101
d) 010001010000 + 010000010111
a)
+
0011
0100
0111
check
(3)
(4)
(7)
0010
0001
0011
0011
0101
1000
check
(23)
(15)
(38)
1000
0001
1001
0110
0011
1001
check
(86)
(13)
(99)
b)
+
c)
+
d)
+
0100
0100
1000
0101
0001
0110
0000
0111
0111
check
(450)
(417)
(867)
Example:
Add the following BCD numbers
a) 1001 + 0100
b) 1001 + 1001
c) 00010110 + 00010101
d) 01100111 + 01010011
14
DNT 231 - Digital System
a)
1001
+
0100
1101
+
0110
0001 0011
(1)
+
Invalid BCD number (>9)
Add 6
Valid BCD number
check
(9)
(4)
(13)
(3)
b)
0001
(1)
1001
1001
0010
0110
1000
(8)
0001
0001
0010
0110
0101
1011
0011
(3)
0110
0001
(1)
+
1
+
+
Invalid BCD number (>9)
Add 6
Valid BCD number
check
(9)
(9)
(18)
c)
+
+
+
right group is invalid (>9)
left group is valid
add 6 to invalid code. Add carry, 0001, to next group.
valid BCD number
d)
0110
0101
1011
+
0110
0001 0010
(1)
(2)
+
0111
0011
1010
0110
0000
(0)
+
Both groups are invalid (>9)
Add 6 to both groups
valid BCD number
15
check
(67)
(53)
120
check
(16)
(15)
(31)