Sie sind auf Seite 1von 14

Digital Logic

Design

Dr. Mona Fahmy Ismail


Ain Shams University
Faculty of Engineering
CSE 314: Logic Design
 Instructor: Mona A.Fahmy Ismail
email: monaismail77@yahoo.com
 TA: Eng. Tamer Ismail
 Course Material & News:
http://www.mech2010.com/vb/forumdisplay.php?f=27

The Course will cover:


 Binary numbers
 Boolean algebra and logic gates
 Combinational logic
 Sequential logic and storage devices
 Registers and counters
 Memory and programmable logic
 Register transfer logic

Attendance
 It is important to attend the lecture. You have a Quiz during it.
 You need to attend at least 75% of the tutorials.
 Not attending this % of tutorials will result in being barred from final exam.

Reference
“Digital Design”, Third Edition; 2002; M. Morris Mano; Pearson Education Asia

Course specifications
 Go to http://eng.shams.edu.eg
 Click on Quality assurance link
 Than click Course specifications
 Go to Course no. 314
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Chapter 1
Binary System
The Chapter
Chapter will cover:
 Binary numbers
 Number base conversion
 Octal and hexadecimal numbers
 Complements
 Binary

Overview
Digital design is concerned with the design and implementation of digital circuits. Digital systems exist
on computers, controllers, communications systems, memory, input and output devices. It deals with
the manipulation of discrete information.

Why Digital in Life?


To transmit any analog signal it may be distorted due to noise. So to avoid that, it has to be converted
to 1’s and 0’s.

Number systems
In a system which its base is b, a positive number N represents the polynomial:

q −1
N = aq - 1 b q -1 + … + a 0 b 0 + … + a -p b -p = ∑a b
i=− p
i
i

Where b is an integer > 1, a’s are integer in the range 0 ≤ ai ≤ b-1. The sequence of digits aq-1 …. a0
constitutes the integral part of N, while the sequence of digits a-1 …. a-p constitutes the fractional part of
it. The least significant digit of N is a-p, while the most significant digit of N is aq-1.
As an example:

(86.4)r = 6* r0 + 8* r1 +4* r -1

(67.23)10 = 6 x 101 + 7 x 100 + 2 x 10-1 + 3 x 10-2

3/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Note: The base is also called radix.


Examples of most important bases:
Base 10 Base 2 Base 8 Base 16
Decimal Binary Octal Hexadecimal
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Conversion of bases:
bases:
Conversion bases are to convert any number N which is represented in base b1 to other base b1.
To convert a number in any base to decimal;
Express (N) b as a polynomial in powers of b and evaluating it using base10 arithmetic.
Examples 1:
1. (C3AF)16 = (F* 160 + A* 161 + 3* 16 2 + C* 163 ) = (15 * 160 + 10 * 161 + 3* 16 2 + 12 * 163 )
= (50095)10
2. (1.11010)2 = (1 * 20 + 1* 2 -1 + 1* 2 -2 + 0* 2 -3 + 1* 2 -4 + 0* 2 -5) = (1.8125)10
3. (432.2)8 = 4 x 82 + 3 x 81 + 2 x 80 + 2 x 8-1 = (282.25)10
4. (101)2 = 1 x 22 + 0 x 21 + 1 x 20 = 4 + 1 = (5)10

To convert a decimal number to any other base:


Consider the integral part separately from the fractional part.
a) Let (N) 10 be the integer part which its value in base b is given by:

(N)10 = aq - 1 b q -1 + … + a 1 b1 + a 0 b 0

4/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

To find ai’s, divided this polynomial by b, the reminder is the least significant digit of the equivalent
number in base b. Divide the its quotient by b, the reminder of this step is the next significant digit.
Repeat these steps till the quotient = 0
Examples 2:
Convert (548)10 to base 8. i Qi ri

0 548/8 68 4
1 68/8 8 4
2 8/8 1 0
(548)10 = (1044) 8 3 1/8 0 1

b) Let (N)10 be a fraction which its value in base b is given by:

( N )10 = a -1 b -1 + a -2 b -2 + ... + a -p b -p
The most significant digit a-1 obtained by multiplying the polynomial by b. If the product < 1, then the
most significant digit = 0, otherwise, it is = the integer part of the product. The next most significant is
found by multiplying the fractional part of the above product by b and determining its integral part, and
so on.
This process does not necessarily terminate.
Example 3:
Convert (0.3125)10 to base 6.

0.3125 × 6 =1.8750 (a-1 = 1)


0. 875 × 6 = 5.25 (a-2 = 5)
0. 25 × 6 = 1.5 (a-3 = 1)
0. 5 × 6 = 3.0 (a-4 = 3)
(0.3125)10 = (0.1513)6

Example 4:
Convert (432.354)10 to base 4.

432 108 0 0.354 × 4 =1.416 (a-1 = 1)


108 27 0 0.416 × 4 = 1.664 (a-2 = 1)
27 6 3 0.664 × 4 = 2.656 (a-3 = 2)
6 1 2 0.656 × 4 = 2.624 (a-4 = 2)
1 0 1 0.624 × 4 = 2.496 (a-5 = 2)
5/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

(432.354)10 = (12300.11222)4

Since 23 = 8 and 24 = 16, so one octal digit can be expressed by three binary digits and one
hexadecimal digit can be represented by 4 binary digits.
Example 5:
Convert (123.4)8 to base 2.
(123.4)8 = (001010011.100)2
Example 6:
Convert (306.D)16 to base 2.
(306.D)16 = (0011 0000 0110.1101)2
Example 7:
Convert (1010110.0101)2 to base 8 and base 16.
(001 010 110.0101)2 = (126.24)8

(0101 0110.0101)2 = (56.5)16


Example 8:
Convert (51)10 to base 2, 8 and base 16.
(51)10 = ( 110 011 )2 = (63)8= (33)16

Example 9:
Convert (63)10 to base 2, 8 and base 16.
(63)10 = ( 111 111 )2 = (77)8= (3F)16

Example 10:
Convert (41)10 to base 8 and base 2.
(41)10 = (51)8= (101001)2

Example 11:
Convert (78)10 to base 16 and base 2.
(78)10 = (4E)16= (01001110)2

Binary Arithmetic:
Bits Sum Carry Difference Borrow Product
a b a+b a-b a .b
0 0 0 0 0 0 0
0 1 1 0 1 1 0
1 0 1 0 1 0 0
1 1 0 1 0 0 1

6/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Binary Addition Binary Multiplication Binary Subtraction


Carry: 1 1 0 0 1 0 101001 101001
× 101 - 101
101001
=========== ===========
011001 101001 100100
=========== 0000000
1000010 10100100
=============
11001101

Complements
It is used for simplifying the subtraction operation. There are two types of complements for any base b
system:
1. b’s Complements.
2. (b-1)’s Complements.

b’s complement
For (N)b and N is positive with an integer part of n digits, the b’s compliant of N is defined as:
bn - N for N≠0
0 for N=0
Example 12:
Find 10’s complement of (520)10 , (0.326)10.
10’s complement of (520)10 = 103 - 520 = 480
10’s complement of (0.326)10 = 1 - 0.326 = 0.674

2’s complement of N:
2’s complement of (N) and N consists of n digits = (2n) - N
Example 13:
Find 2’s complement of (1001) 2 = (10000) 2 – (1001) 2 = (0111) 2

(b-1)’s complement
For (N)b and N is positive with an integer part of n digits, and m digits of the fractional part, the (b-1)’s
compliant of N is defined as:
bn – b-m - N
Example 14:
Find 9’s complement of (25.639)10
9’s complement of (25.639)10 = 102 - 10-3 – 25.639 = 99.999 – 25.639 = 74.36

7/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

1’s complement of N:
1’s complement of (N) and N consists of n digits = (2n - 1) - N
Example 15:
Find 1’s complement of (1001) 2 = (10000 - 1) - 1001 = (0110) 2

Subtraction using b’s complement


The subtraction of two positive numbers (M-N), both of base b can be done as follows:
1. Add M to b’s complement of N.
2. Inspect the result obtained in step 1 for an end carry:
 If an end carry occurs, discard it. (+ ve answer)
 If an end carry does not occur, take the b’s complement of the number obtained in step 1
and place a negative sign in front of it. (- ve answer)

Example 16:
Using 10’s complement, subtract (72532 – 3250) 10
M = 72532, N= 03250 10’s complement of N = 96750
∴ 7 2 5 3 2
End carry 9 6 7 5 0
===============
1 6 9 2 8 2

Example 17:
Using 10’s complement, subtract (3250 - 72532) 10
M = 03250, N= 72532 10’s complement of N = 27468
∴ 0 3 2 5 0
No carry 2 7 4 6 8
===============
0 3 0 7 1 8 -69282

using 2’s complement


Example 18: Compute X - Y, where X = 1011, Y = 1010
X ⇒ 1011
C2(Y) ⇒ 0110
===============
10001 ⇒ X-Y = 0001

8/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Example 19: Compute X-Y, where X = 1011, Y = 1110


X ⇒ 1011
C2(Y) ⇒ 0010
===============
1101 ⇒ X-Y = C2(1101) = - 11

Subtraction using (b -1)’s


1)’s complement
The subtraction of two positive numbers (M-N), both of base b can be done as follows:
1. Add M to (b-1)’s complement of N.
2. Inspect the result obtained in step 1 for an end carry:
 If an end carry occurs, add 1 to the least significant digit.
 If an end carry does not occur, take the (b-1)’s complement of the number obtained in step 1
and place a negative sign in front of it.
Example 20:
Using 9’s complement, subtract (72532 – 3250) 10
M = 72532, N= 03250 9’s complement of N = 96749
∴ 7 2 5 3 2
End carry 9 6 7 4 9
===============
1 6 9 2 8 1
1+
===============
6 9 2 8 2
Example 21:
Using 9’s complement, subtract (3250 - 72532) 10
M = 03250, N= 72532 9’s complement of N = 27467
∴ 0 3 2 5 0
No carry 2 7 4 6 7
===============
0 3 0 7 1 7 -69282

Binary Codes
It is the convenient code to work with decimal number system especially when the communication
between man and machine.

Weighted Code:
The main characteristic of the weighted code is that each binary digit is assigned a weight. For each
group of bits corresponding to decimal number, the sum of those bits = the decimal number.
9/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Examples of some weighted code:

Decimal digit Binary Coded Decimal (BCD) W4 W3 W2 W1


8 4 2 1 2 4 2 1 6 4 2 -3
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1 0 1 0 1
2 0 0 1 0 0 0 1 0 0 0 1 0
3 0 0 1 1 0 0 1 1 0 1 1 1
4 0 1 0 0 0 1 0 0 0 1 0 0
5 0 1 0 1 1 0 1 1 1 0 1 1
6 0 1 1 0 1 1 0 0 1 0 0 0
7 0 1 1 1 1 1 0 1 1 1 0 1
8 1 0 0 0 1 1 1 0 1 0 1 0
9 1 0 0 1 1 1 1 1 1 1 1 1
For self complementing codes, the sum of the weights = 9

Non Weighted Code:


ASCII is an example of non weighted code. Each ASCII character gets 7 bits like:
A 100 0001
a 110 0001
Other examples of some non weighted code:
Decimal digit Excess-3 Cyclic Gray
0 0 0 1 1 0 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 1 0 0 0 1
2 0 1 0 1 0 0 1 1 0 0 1 1
3 0 1 1 0 0 0 1 0 0 0 1 0
4 0 1 1 1 0 1 1 0 0 1 1 0
5 1 0 0 0 1 1 1 0 0 1 1 1
6 1 0 0 1 1 0 1 0 0 1 0 1
7 1 0 1 0 1 0 0 0 0 1 0 0
8 1 0 1 1 1 1 0 0 1 1 0 0
9 1 1 0 0 1 1 0 1 1 1 0 1

Cyclic code: It is the code that has at maximum of 1 bit changes per increment.
Reflected Code: It is another type of cyclic code.

10/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

0 0 0 0 0 0 0 0 0 0
1 0 1 0 0 1 0 0 0 1
1 1 0 1 1 0 0 1 1
1 0 0 1 0 0 0 1 0
1 1 0 0 1 1 0
1 1 1 0 1 1 1
1 0 1 0 1 0 1
1 0 0 0 1 0 0
1 1 0 0
1 1 0 1
1 1 1 1
1 1 1 0
1 0 1 0
1 0 1 1
1 0 0 1
1 0 0 0

Gray Code:
It is type of cyclic code. Assume that the gray code is represented by gn gn-1 gn-2 … g1 g0. It is built
based on the binary code that is represented by bn bn-1 bn-2 … b1 b0.
Where gi = bi ⊕ bi+1 0 ≤ i ≤ n-1.
gn = bn
where:
0⊕0=0 1⊕1=0 0⊕1=1 1⊕0=1
b5 b4 b3 b2 b1 b0
1 0 1 1 0 1

⊕ ⊕ ⊕ ⊕ ⊕
1 1 1 0 1 1
g5 g4 g3 g2 g1 g0

11/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Error Detection and Correction:


Error Detection:
To detect single error, one bit must be added to the number of bits representing the code as shown:
Decimal digit Even parity BCD 2-out-of-5
8 4 2 1 P 0 1 2 4 7
0 0 0 0 0 0 0 0 0 1 1
1 0 0 0 1 1 1 1 0 0 0
2 0 0 1 0 1 1 0 1 0 0
3 0 0 1 1 0 0 1 1 0 0
4 0 1 0 0 1 1 0 0 1 0
5 0 1 0 1 0 0 1 0 1 0
6 0 1 1 0 0 0 0 1 1 0
7 0 1 1 1 1 1 0 0 0 1
8 1 0 0 0 1 0 1 0 0 1
9 1 0 0 1 0 0 0 1 0 1

Error Correcting Code:


To correct a single error, the minimum distance between any two code words in this code is 3.
Hamming code will be discussed here. To construct a Hamming code, assume that we have m digit
binary massage and k parity check digits, denoted by p1, p2, …, pk are added to form an (m + k) digit
code. The most significant digit of the (m + k) code is 1, while the least significant one is the (m+k)th ,
where k must satisfy the inequality 2k ≥ m + k +1, and the parity bits must be in the position 2i , where
0 ≤ i < k and the other positions are for the massage.
For BCD and using even parity: BCD has m = 4, so, 2k ≥ 4 + k +1 ⇒ 2k ≥ 5 + k ⇒ k = 3
P1 is selected so as to establish parity in positions 1,3,5,7
P2 is selected so as to establish parity in positions 2,3,6,7
P3 is selected so as to establish parity in positions 4,5,6,7

12/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Decimal digit Position Number


1 2 3 4 5 6 7
p1 p2 m1 P3 m2 m3 m4
0 0 0 0 0 0 0 0
1 1 1 0 1 0 0 1
2 0 1 0 1 0 1 0
3 1 0 0 0 0 1 1
4 1 0 0 1 1 0 0
5 0 1 0 0 1 0 1
6 1 1 0 0 1 1 0
7 0 0 0 1 1 1 1
8 1 1 1 0 0 0 0
9 0 0 1 1 0 0 1

The parity checks c1, c2, …, ck, indicate the location of error by its value. It also indicates that there is
no error if its value = 0.

Error position Position Number


C1 C2 C3
0 (no error) 0 0 0
1 0 0 1
2 0 1 0
3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1
Assume that we have the following sequence 1 1 0 0 0 0 1
C1 C2 C3 = 1 0 0 =4 ⇒ there is an error in position 4
So, the correct message is 1 1 0 1 0 0 1

13/ 14
Ain Shams University Faculty of Engineering
Computer and Systems Department Digital Design
Chapter 1
Dr. Mona Fahmy 2008/2009

Binary Logic
Binary logic deals with variables with 2 states (1 → yes, 0 → no)
3 Basic operations:
X Y AND OR NOT
X●Y X+Y X′

0 0 0 0 1
0 1 0 1 1
1 0 0 1 0
1 1 1 1 0

Logic in the physical world

Example of Binary Signals

14/ 14

Das könnte Ihnen auch gefallen