0907231 Digital Logic
Dr. Walid Abu-Sufah
Read Chapter 1: Sections 1-7
Based on notes by A. Lastra and slides provided by the text publisher
Instructor (Section 3)
• Instructor: Dr. Walid Abu-Sufah• Email: [email protected]• Office: CPE 417• Office Hours: Sunday, Tuesday,
Wednesday 1-2• Course web site: http://www2.ju.edu.jo/sites/academic/
abusufah/material/cpe231_spr13/index.html
CPE 432 Computer Design
2
4
Textbook
• Logic and Computer Design Fundamentals, M. Morris Mano and Charles R. Kime (latest edition). Prentice Hall.
5
Grading Policy
• 4 Quizzes 16%• 4 Homeworks 4%• Mid-term Exam 30%
♦ Saturday, March 30; 2-3:15
• Final Exam 50%♦ Monday, May 20; 2-4 PM
• Visit course website for updates on dates of exams, quizzes, and homeworks
6
Policies: The Course Web Site
• Class announcements, such as homework/quizzes dates and changes in assignments, will be posted on the Web.
• You are therefore responsible for checking the course web site. If you make an error because you did not check the Web, I will hold you fully responsible.
7
Policies: Homework and Quizzes
• Four homeworks• Due at the beginning of the first lecture in
the weeks indicated in the course calendar on the website.
• No late homework will be accepted.• One quiz will be given at the beginning of the
same lecture when each of the four homeworks is collected.
• For each student, the lowest of the 4 grades of quizzes will be dropped.
• As a result, there will be no make-up quizzes for any reason.
8
Policies: Makeup Midterm There will be no make-up for the midterm. In
case of medical/ or other DISABLING emergencies, the instructor should be notified BEFORE the midterm and his approval for missing the midterm should be obtained before the midterm. If for any reason the instructor could not be reached, the department secretary should be notified before the midterm. The phone number is 535-5000 Extension 23000.
9
Policies: Grading Corrections
Ask the instructor for any grading correction requests within a week of returning the exam/quiz papers. After that, your grade will not be adjusted. If you find any mistake in grading, please let the instructor know. Your grade will not be lowered.
10
Policies: Class Attendance
Class attendance will be taken. University regulations regarding attendance will be strictly enforced. If you miss class, you must obtain the covered material from a willing classmate and/or the course web site. The instructor will not be available (during office hours or other times) to repeat material covered.
11
Policies: Academic Honesty
• Your work in this class must be your own.
• Penalties for excessive collaboration and cheating are severe.
• Sharing homework answers is forbidden
12
Today’s Topics
• Material from Chapter 1♦ What is digital logic?♦ Binary signaling♦ Number systems♦ Codes
13
What’s Course About?
• Digital logic focusing on the design of computers
• Stay above transistor level• High-level Hardware Description
Language, HDL♦ Allows Staying above logic gate level
♦ Will be covered in the lab course
15
Discrete Data
• Some data inherently discrete♦ Names (sets of letters)
• Some quantized♦ Music recorded from microphone
♦ Note that other examples like music from CD or electronic keyboard already quantized
Chapter 1 16
INFORMATION REPRESENTATION - Signals
Information variables represented by physical quantities.
For digital systems, the variables take on discrete values.
Two level, or binary values are used in digital systems
Binary values are represented by:• digits 0 and 1
• words (symbols) False (F) and True (T)
• words (symbols) Low (L) and High (H)
• and words On and Off.
18
Signal Examples Over Time
Analog
Asynchronous
Synchronous
Time
Continuous in value &
time
Discrete in value & continuous
in time
Discrete in value &
time
Digital
20
Binary Numbers
•Strings of binary digits (“bits”)♦ One bit can store a number from the set
(0 , 1)♦ n bits can store numbers from 0 to 2n-1
21
Binary – Powers of 2
•Positional representation •Each digit represents a power of 2
So 101 binary is
1 • 22 + 0 • 21 + 1 • 20
or 1 • 4 + 0 • 2 + 1 • 1 = 5
22
Converting Binary to Decimal
•Easy, just multiply digit by power of 2
• Just like a decimal number is represented
•Example follows
23
Binary Decimal Example
7 6 5 4 3 2 1 0
27 26 25 24 23 22 21 20
128
64 32 16 8 4 2 1
1 0 0 1 1 1 0 0
128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156 128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156
What is 10011100 in decimal?What is 10011100 in decimal?
24
Decimal to Binary
•A little more work than binary to decimal
•Some examples♦ 3 = 2 + 1 = 11 (that’s 1•21 + 1•20)♦ 5 = 4 + 1 = 101 (that’s 1•22 + 0•21 +
1•20)
25
Algorithm – Decimal to Binary
1. Find largest power-of-two smaller than decimal number
2. Make the appropriate binary digit a ‘1’
3. Subtract the “power of 2” from decimal
4. Do the same thing again
26
Decimal Binary Example
• Convert 28 decimal to binary
32 is too large, so use 16Binary 10000 Decimal 28 – 16 = 12
Binary 11000 Decimal 12 – 8 = 4Next is 8
Binary 11100 Decimal 4 – 4 = 0Next is 4
27
Hexadecimal
• Strings of 0s and 1s too hard to write
• Use base-16 or hexadecimal – 4 bitsDec Bin Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
Dec Bin Hex
8 1000 8
9 1001 9
10 1010 ?
11 1011 ?
12 1100 ?
13 1101 ?
14 1110 ?
15 1111 ?
28
Hexadecimal
• Letters to represent 10-15
Dec Bin Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
Dec Bin Hex
8 1000 8
9 1001 9
10 1010 a
11 1011 b
12 1100 c
13 1101 d
14 1110 e
15 1111 f
•Power of 2Power of 2
•Size of byteSize of byte
Why useWhy usebase 16?base 16?
29
Hex to Binary
• Convention – write 0x before number:0x2ac or (2ac)16
• Hex to Binary – just convert digits
Bin Hex
0000 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
0x2ac0x2ac
00100010 10101010 11001100
(2ac)(2ac)16 16 = 0x2ac = 001010101100= 0x2ac = 001010101100
No magic – remember hex digit = 4 bitsNo magic – remember hex digit = 4 bits
30
Binary to Hex
• Just convert groups of 4 bits
Bin Hex
0000 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
101001101111011101001101111011
10111011
55 33 77 bb
101001101111011 = 0x537b = (537b)101001101111011 = 0x537b = (537b)1616
0101 0101 0111 0111 0011 0011
31
Hex to Decimal• Just multiply each hex digit
by a decimal value which is its positional weight, and add the results.
163 162 161 160
4096 256 16 1
0x2ac0x2ac
2 2 • 256• 256 + 10 + 10 • 16• 16 + 12 + 12 • 1• 1 = 684= 684
Dec Hex
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 a
11 b
12 c
13 d
14 e
15 f
32
Decimal to Hex
Analogous to decimal binary.1. Find largest power-of-16
smaller than decimal number2. Divide by power-of-16. The
integer result is hex digit.3. The remainder is new decimal
number.4. Do the same thing again
33
Decimal to Hex
163 162 161 160
4096 256 16 1
Dec Hex
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 a
11 b
12 c
13 d
14 e
15 f
684684
684/256 = 2684/256 = 2 0x2__
684%256 = 172684%256 = 172
172/16 = 10 = a172/16 = 10 = a 0x2a_172%16 = 12 = c172%16 = 12 = c 0x2ac
34
Octal
•Octal is base 8•Similar to hexadecimal
♦ Conversions
•Less convenient for use with 8-bit bytes
Chapter 1 35
In General:NUMBER SYSTEMS – Representation
Positive radix, positional number systems A number with radix r is represented by a
string of digits: An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m 1 A- m
in which 0 Ai < r and . is the radix point.
The string of digits represents the power series:
(Number)r = j = - m
jj
i
i = 0i rArA
(Integer Portion) + (Fraction Portion)
i = n - 1 j = - 1
Chapter 1 36
Number Systems – Examples
General Decimal Binary
Radix (Base) r 10 2
Digits 0 => r - 1 0 => 9 0 => 1
0
1
2
3
Powers of 4
Radix 5
-1
-2
-3
-4
-5
r0
r1
r2
r3
r4
r5
r -1
r -2
r -3
r -4
r -5
1
10
100
1000
10,000
100,000
0.1
0.01
0.001
0.0001
0.00001
1
2
4
8
16
32
0.5
0.25
0.125
0.0625
0.03125
Chapter 1 37
Special Powers of 2
210 (1024) is Kilo, denoted "K"
220 (1,048,576) is Mega, denoted "M"
230 (1,073, 741,824)is Giga, denoted "G"
240 (1,099,511,627,776 ) is Tera, denoted “T"
38
Conversion Between Bases
Method 2 To convert from one base to another:
1) Convert the Integer Part
2) Convert the Fraction Part
3) Join the two results with a radix point
39
Example: Convert 46.687510 To Base 2
Convert 46 to Base 2
Convert 0.6875 to Base 2:
Join the results together with the radix point:
40
Conversion Details To Convert the Integral Part:
Repeatedly divide the number by the new radix and save the remainders. The digits for the new radix are the remainders in reverse order of their computation.
To Convert the Fractional Part:
Repeatedly multiply the fraction by the new radix and save the integer digits that result. The digits for the new radix are the integer digits in order of their computation.
If the new radix is > 10, then convert all integers > 10 to digits A, B, …
41
Additional Issue - Fractional Part
Note that in this conversion, the fractional part became 0 as a result of the repeated multiplications.
In general, it may take many bits to get this to happen or it may never happen.
Example: Convert 0.6510 to N2
• 0.65 = 0.1010011001001 …
• The fractional part begins repeating every 4 steps yielding repeating 1001 forever!
Solution: Specify number of bits to right of radix point and round or truncate to this number.
42
Arithmetic -- addition
• Binary similar to decimal arithmetic
0 1 1 0 0
+ 1 0 0 0 1
1 1 1 0 1
No carries 1 0 1 1 0 0
1 0 1 1 0
+ 1 0 1 1 1
1 0 1 1 0 1
Carries
1+1 is 2 (or 102), which results in a carry
43
Arithmetic -- subtraction
1 0 1 1 0
- 1 0 0 1 0
0 0 1 0 0
No borrows 0 0 1 1 0
1 1 1 1 0
- 1 0 0 1 1
0 1 0 1 1
Borrows
0 - 1 results in a borrow
44
Arithmetic -- multiplication
1 0 1 1
0 0 0 0
1 0 1 1
1 1 0 1 1 1
Successive additions of multiplicand or zero,multiplied by 2 (102).
Note that multiplication by 102 just shifts bits left.
1 0 1 1
X 1 0 1
multiplicand
multiplier
45
Hexadecimal Arithmetic
• Similar• If you’re doing by hand, easiest
to convert each set of digits to decimal and back
Chapter 1 46
DECIMAL CODES - Binary Codes for Decimal Digits
Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray 0 0000 0011 0000 0000 1 0001 0100 0111 0100 2 0010 0101 0110 0101 3 0011 0110 0101 0111 4 0100 0111 0100 0110 5 0101 1000 1011 0010 6 0110 1001 1010 0011 7 0111 1010 1001 0001 8 1000 1011 1000 1001 9 1001 1100 1111 1000
There are over 8,000 ways that you can chose 10 from the 16 binary numbers of 4 bits. A few are useful:
47
BCD
• Binary Coded Decimal• Decimal digits stored in binary
♦ Four bits/digit♦ Like hex, except stops at 9♦ Example
931 is coded as 1001 0011 0001
Chapter 1 48
Warning: Conversion or Coding?
Do NOT mix up conversion of a decimal number to a binary number with coding a decimal number with a BINARY CODE.
1310 = 11012 (This is conversion)
13 0001|0011 (This is coding)
49
Other Codes Exist
• Non positional• Example: 3-bit Gray Code
♦ 000,001,011,010,110,111,101,100• Binary Gray code for octal digits
♦ Only one bit changes at a time
♦ Actually there’s a family of Gray codes
Chapter 1 50
GRAY CODE – Decimal
Decimal 8,4,2,1 Gray 0 0000 0000 1 0001 0100 2 0010 0101 3 0011 0111 4 0100 0110 5 0101 0010 6 0110 0011 7 0111 0001 8 1000 1001 9 1001 1000
51
Character Codes
• From numbers to letters• ASCII
♦ Stands for American Standard Code for Information Interchange
♦ Only 7 bits defined
• Unicode
53
Even Parity
• Sometimes high-order bit of ASCII coded to enable detection of errors
• Even parity – set bit to make number of 1’s even
• Examples♦ A (100 0001) with even parity is 0100 0001♦ C (100 0011) with even parity is 1100 0011
54
Odd Parity
• Similar except make the number of 1’s odd
• ExamplesA (100 0001) with odd parity is 1100 0001C (100 0011) with odd parity is 0100 0011
Recommended