241 CSM-4-Digital Logic-Lecture 5
241 CSM-4-Digital Logic-Lecture 5
241 CSM-4-Digital Logic-Lecture 5
Digital Logic
Lecture 5
1
Conversion from decimal to base b:
(N)10 (?)b
Procedure:
• Convert the Integer Part
• Convert the Fraction Part
• Join the two results with the new radix point
2
Chapter 1 2
Converting fraction from decimal to base b:
Repeatedly multiply the integer by the new base b and save the integer part of
the result (will never exceed b) until 0 fraction or enough digits
The digits for the new base are those integers with the MS digit being
that computed first
(0.6875)10 = (??)2
radix point
p. 50
4
Example: Convert 153.51310to Base 8,
rounding the resulting fraction to 3 octaldigits
1. Convert Integer Part: 153 to Base 8
= (1011010110.0101111)2
Appended 0‟s
= (0 1011010110.0101111 00 2
0 = (1 3 2 6 . 2 7 4 ))
8
7
Chapter 1 7
Binary Addition
One bit addition:
0 0 1 1 augend /aw-jend/
+0 +1 + 0 +1 addend
----- ------ ------ ------
0 1 1 2 sum
10
carry
KFUPM
Binary Addition (cont.)
KFUPM
Binary Subtraction
One bit subtraction:
0 0 1 1 minuend /men-u-end/
-0 -1 - 0 -1 subtrahend /sub-tra-hend/
----- ------ ------ ------
0 1 1 0 difference
KFUPM
Binary Subtraction (cont.)
Subtract 101 - 011 Larger binary numbers Verify In
1 decimal,
11 11
borrow 783
0101 1 1 0 0 0 0 1 1 11 borrow
- 490
- 0 11 - 0 1 1 1 1 0 1 0 10 ---------
-------------------------- -------------------------- difference 293
difference
010 0100100101
KFUPM
Binary Multiplication
Multiply 1011 with 101:
Rules (short cut):
1011 multiplicand
1. A ‘1’ digit in the multiplier
x 101 multiplier implies a simple copy of the
----------------- multiplicand
KFUPM
Hexadecimal addition
Add (59F)16 and (E46)16
1 1 Carry
KFUPM
Octal Multiplication
Multiply (762)8 with(45)8
Carry
KFUPM
Multiplication (2 of 3)
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
15
Multiplication (3 of 3)
17
17
Binary subtraction (cont)
18
18
Binary subtraction (cont)
19
19
1’s Complement
20
20
2’s complement
21
21
Operation with 2’scomplement
• Add 4 and -6
• Will use the 2‟s complement of -6 or1010
– 4 0100
– -6 1010
– 1110
• And taking the 2‟s complement of 1110get
0001 + 1 = 0010
22
22
A 2’s complement table for 4bits
• Listing the
values
represented.
23
23
Human perception
24
24
Binary Coded Decimal (BCD)
Decimal digit 0 1 2 3 4
BCD 0000 0001 0010 0011 0100
Decimal digit 5 6 7 8 9
BCD 0101 0110 0111 1000 1001
25
Binary Coded Decimal (BCD)
Decimal digit 0 1 2 3 4
BCD 0000 0001 0010 0011 0100
Decimal digit 5 6 7 8 9
BCD 0101 0110 0111 1000 1001
Examples:
(234)10 = (0010 0011 0100)BCD
(7093)10 = (0111 0000 1001 0011)BCD
(1000 0110)BCD = (86)10
(1001 0100 0111 0010)BCD= (9472)10
Notes: BCDis not equivalent tobinary.
Example: (234)10 =(11101010)2
26
BCD operation
27
27
Another
• A second example
– 3 0011
– +3 0011
– Getting 6 or 0 1 1 0
– And in range and a BCDdigit representation
28
28
And now
• Consider 5 + 5
• 5 0101
• +5 0101
• giving 1 0 1 0 which is binary 10 but not
a BCDdigit!
• What to do?
• Try adding 6??
29
29
Adding 6
30
30
Another carry example
• Add 7 + 6
– have 7 0 1 1 1
– plus 6 0 1 1 0
– Giving 1 1 0 1 and again out of range
– Adding 6 0 1 1 0
– Giving 1 0 0 1 1 so a 1 carries out to the next BCD
digit
– FINALBCDanswer 0001 0011 or 1310
31
31
Multibit BCD
33
33
Still Continuing multibit
34
34
Gray Codes
37
37
The Gray Code
0000 1100
0
0001 1101
0
001
01 1111
0
001
00 0110
1
1010
0
0010
1011
0
0011
1001
0
0001
1000
0
00
100
39
The Gray Code
sensors
mis-aligned mis-aligned
sensors sensors
1 Gray 1 1 Gray 1 1 1 Gray
1 0 1 + 1 0 Binary 1 0 1 1 + 0 Binary
1 1 1 0 Gray 1 1 1 0 1 Gray
(10110)2 = (11101)Gray
41
Binary-to-Gray Code Conversion
Gray-to-Binary Conversion
1 1 0 1 1 Gray 1 1 0 1 1 Gray
+ +
1 0 0 1 Binary 1 0 0 1 0 Binary
(11011)Gray = (10010)2
43
Gray-to-Binary Conversion
Alphanumeric Codes
• Encoding of 123
– 011 0001 011 0010 011 0011
• Encoding of Joanne
– 100 1010 110 1111 110 0001
– 110 1110 110 1110 110 0101
48
46
Alphanumeric Codes
49
Alphanumeric Codes
ASCII table:
MSBs
LSBs 000 001 010 011 100 101 110 111
0000 NUL DLE SP 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 “ 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EOT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB „ 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 O RS . > N ^ n ~
1111 SI US / ? O _ o DEL
50
Thank you
51