CENG 203 Digital Design Lecturer: Asc. Prof. Dr. Asaf ŞAHİN CATALOG DESCRIPTION: This course provides a modern introduction to logic design and the basic building blocks used in digital systems, in particular digital computers. It starts with a discussion of combinational logic: logic gates, minimization techniques, arithmetic circuits, and modern logic devices such as field programmable logic gates. The second part of the course deals with sequential circuits: flip-flops, synthesis of sequential circuits, and case studies, including counters, registers, and random access memories. State machines will then be discussed and illustrated through case studies of more complex systems using programmable logic devices. Different representations including truth table, logic gate, timing diagram, switch representation, and state diagram will be discussed. OBJECTIVES: Student will learn: • to apply the principles of Boolean algebra to manipulate and minimize logic expressions. • to use K-maps to minimize and optimize two-level logic functions up to 5 variables. • the operation of latches, flip-flops, counters, registers, and register transfers. • to analyze the operation of sequential circuits built with various flip-flops. • the concepts of datapaths, control units, and micro-operations and building blocks of digital systems. In addition, student will learn to design: • two-level logic functions with AND, OR, NAND, NOR and XOR gates with minimum number of gate delays or literals. • to design combinational circuits using decoders, ROM and transmission gates. • the operation of state-of-the-art components to design and build complex digital systems. • such as memories, PLA, PALs and programmable logic devices (such as FPGAs). • to use state machine diagrams to design finite state machines using various types of flip- flops and combinational circuits with prescribed functionality. GRADING POLICY: Students will be graded based on 1 midterm exam (30% of the total grade), 1 final exam (30% of the total grade), quizzes (25% of the total grade), and lab work and assignments (15% of the total grade). TEXTBOOKS: 1.) Fundamentals of Digital Logic with VHDL Design, Brown and Vransic WEEK TOPICS 1 Number systems and conversion 2 Boolean Algebra 3 Boolean Algebra 4 Minterms Maxterms 5 Karnaugh Maps 6 Multi level Gate Circuits, NAND NOR only design 7 Combinational Circuits 8 Midterm Exam 9 Multiplexers Decoders 10 Programmable Logic Devices 11 Latches and Flip Flops 12 Registers and Counters 13 Analysis of clocked sequential circuits 14 Derivation of state graphs and tables 15 Reduction of State Tables and assignment
97
Embed
CENG 203 Digital Design...– Pair of wires where “0”/“1” distinguished by which has higher voltage (differential) – Magnetic orientation signifies “0” or “1” •
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CENG 203 Digital Design Lecturer: Asc. Prof. Dr. Asaf ŞAHİN CATALOG DESCRIPTION: This course provides a modern introduction to logic design and the basic building blocks used in digital systems, in particular digital computers. It starts with a discussion of combinational logic: logic gates, minimization techniques, arithmetic circuits, and modern logic devices such as field programmable logic gates. The second part of the course deals with sequential circuits: flip-flops, synthesis of sequential circuits, and case studies, including counters, registers, and random access memories. State machines will then be discussed and illustrated through case studies of more complex systems using programmable logic devices. Different representations including truth table, logic gate, timing diagram, switch representation, and state diagram will be discussed. OBJECTIVES: Student will learn:
• to apply the principles of Boolean algebra to manipulate and minimize logic expressions. • to use K-maps to minimize and optimize two-level logic functions up to 5 variables. • the operation of latches, flip-flops, counters, registers, and register transfers. • to analyze the operation of sequential circuits built with various flip-flops. • the concepts of datapaths, control units, and micro-operations and building blocks of digital
systems. In addition, student will learn to design:
• two-level logic functions with AND, OR, NAND, NOR and XOR gates with minimum number of gate delays or literals.
• to design combinational circuits using decoders, ROM and transmission gates. • the operation of state-of-the-art components to design and build complex digital systems. • such as memories, PLA, PALs and programmable logic devices (such as FPGAs). • to use state machine diagrams to design finite state machines using various types of flip-
flops and combinational circuits with prescribed functionality. GRADING POLICY: Students will be graded based on 1 midterm exam (30% of the total grade), 1 final exam (30% of the total grade), quizzes (25% of the total grade), and lab work and assignments (15% of the total grade). TEXTBOOKS: 1.) Fundamentals of Digital Logic with VHDL Design, Brown and Vransic
WEEK TOPICS 1 Number systems and conversion 2 Boolean Algebra 3 Boolean Algebra 4 Minterms Maxterms 5 Karnaugh Maps 6 Multi level Gate Circuits, NAND NOR only design 7 Combinational Circuits 8 Midterm Exam 9 Multiplexers Decoders
10 Programmable Logic Devices 11 Latches and Flip Flops 12 Registers and Counters 13 Analysis of clocked sequential circuits 14 Derivation of state graphs and tables 15 Reduction of State Tables and assignment
Lecture 01 - Intro
• Represent numbers and perform arithmetic in bases 2, 8, 10, and 16. • Encode symbols and numbers in binary codes. • Add and subtract using 2’s complement code. • Evaluate and simplify logical functions using Boolean algebra. • Analyze and design combinatorial circuits. • Simplify combinatorial circuits using Karnaugh maps. • Understand Flip Flop and other memory implementation gates. • Analyze and design modular combinatorial logic circuits containing multiplexers, demultiplexers, 7-segments display decoders and adders. • Use the concepts of state and state transition for analysis and design of sequential circuits. • Use the functionality of flip-flops for analysis and design of sequential circuits.
Logic Design Course Objectives
Logic w/out
Memory
Logic with
Memory
Lecture 01 - Intro
What is Logic Design? • What is design?
– Given problem spec, solve it with available components – While meeting quantitative (size, cost, power) and qualitative
(simplicity, elegance)
• What is logic design? – Choose digital logic components to perform specified control,
data manipulation, or communication function and their interconnection
– Which logic components to choose? Many implementation technologies (fixed-function components, programmable devices, individual transistors on a chip, etc.)
– Design optimized/transformed to meet design constraints
Lecture 01 - Intro
What is Digital Hardware? • Devices that sense/control wires carrying digital values
(physical quantity interpreted as “0” or “1”) – Digital logic: voltage < 0.8v is “0”, > 2.0v is “1” – Pair of wires where “0”/“1” distinguished by which has higher
voltage (differential) – Magnetic orientation signifies “0” or “1”
• Primitive digital hardware devices – Logic computation devices (sense and drive)
• Two wires both “1” - make another be “1” (AND) • At least one of two wires “1” - make another be “1” (OR) • A wire “1” - then make another be “0” (NOT)
– Memory devices (store) • Store a value • Recall a value previously stored
Lecture 01 - Intro
What is the Current State of Digital Design? • Changes in industrial practice
– Larger designs – Shorter time to market – Cheaper products
• Scale – Pervasive use of computer-aided design tools over hand
methods – Multiple levels of design representation
• Time – Emphasis on abstract design representations – Programmable rather than fixed function components – Automatic synthesis techniques – Importance of sound design methodologies
• Cost – Higher levels of integration – Use of simulation to debug designs
Lecture 01 - Intro
Computation: Abstract vs. Implementation
• Computation as a mental exercise (paper, programs) • vs. implementation with physical devices using voltages
to represent logical values • Basic units of computation:
– Representation: "0", "1" on a wire set of wires (e.g., for binary integers)
– Assignment: x = y – Data operations: x + y – 5 – Control:
Sequential statements: A; B; C Conditionals: if x == 1 then y Loops: for ( i = 1 ; i == 10, i++) Procedures: A; proc(...); B;
• Study how these are implemented in hardware and composed into computational structures
Lecture 01 - Intro
Close switch (if A is “1” or asserted) and turn on light bulb (Z)
Open switch (if A is “0” or unasserted) and turn off light bulb (Z)
Switches: Basic Element of Physical Implementations
• Implementing a simple circuit (arrow shows action if wire changes to “1”):
Z ≡ A
A Z
Lecture 01 - Intro
AND
OR
Z ≡ A and B
Z ≡ A or B
A B
A
B
Switches (cont’d)
• Compose switches into more complex ones (Boolean functions):
Lecture 01 - Intro
Switching Networks
• Switch settings – Determine whether conducting path exists to light the
bulb
• To build larger computations – Use bulb (output of the network) to set other switches
Technology State 0 State 1 Relay logic Circuit Open Circuit Closed CMOS logic 0.0-1.0 volts 2.0-3.0 volts Transistor transistor logic (TTL) 0.0-0.8 volts 2.0-5.0 volts Fiber Optics Light off Light on Dynamic RAM Discharged capacitor Charged capacitor Nonvolatile memory (erasable) Trapped electrons No trapped electrons Programmable ROM Fuse blown Fuse intact Bubble memory No magnetic bubble Bubble present Magnetic disk No flux reversal Flux reversal Compact disc No pit Pit
Mapping Physical to Binary World
Lecture 01 - Intro
inputs outputs system
Combinational vs. Sequential Digital Circuits
• Simple model of a digital system is a unit with inputs and outputs:
• Combinational means "memory-less" – Digital circuit is combinational if its output values
only depend on its inputs
Lecture 01 - Intro
Binary Representation
• The basis of all digital data is binary representation. • Binary - means ‘two’ – 1, 0 – True, False – Hot, Cold – On, Off • We must be able to handle more than just values for real world problems – 1, 0, 0.5 – True, False, Maybe – Hot, Cold, Luke Warm, Cool – On, Off, Leaky
Lecture 01 - Intro
Number Systems
To talk about binary data, we must first talk about number systems – A digit in base 10 ranges from 0 to 9. – A digit in base 2 ranges from 0 to 1 (binary number system). A digit in base 2 is also called a ‘bit’. – A digit in base R can range from 0 to R-1 – A digit in Base 16 can range from 0 to 16-1 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to represent values 10 to 15. Base 16 is also called Hexadecimal or just ‘Hex’.
Lecture 01 - Intro
Positional Notation Value of number is determined by multiplying each digit by a weight and then summing. The weight of each digit is a POWER of the BASE and is determined by position. 953.78 = 9 x 102 + 5 x 101 + 3 x 100 + 7 x 10-1 + 8 x 10-2
210 = 1024 = 1 K 220 = 1048576 = 1024 K = 210 x 210 = 1 M (1 Megabits) 230 = 1073741824 = 1 G (1 Gigabits)
Lecture 01 - Intro
Conversion of Any Base to Decimal
Converting from ANY base to decimal is done by multiplying each digit by its weight and summing. Binary to Decimal, % 1011.11 = 1x2^3 + 0x2^2 + 1x2^1 + 1x2^0 + 1x2^-1 + 1x2^-2 = 8 + 0 + 2 + 1 + 0.5 + 0.25= 11.75 Hex to Decimal, $ A2F = 10x16^2 + 2x16^1 + 15x16^0 = 10 x 256 + 2 x 16 + 15 x 1 = 2560 + 32 + 15 = 2607
Lecture 01 - Intro
Conversion of Decimal Integer to ANY Base Divide Number N by base R until quotient is 0. Remainder at EACH step is a digit in base R, from Least Significant digit to Most significant digit. Convert 53 to binary 53/2 = 26, rem = 1 Most Significant Digit 26/2 = 13, rem = 0 13/2 = 6 , rem = 1 6 /2 = 3, rem = 0 3/2 = 1, rem = 1 1/2 = 0, rem = 1 Least Significant Digit 53 = % 110101 = 1x2^5 + 1x2^4 + 0x2^3 + 1x2^2 + 0x2^1 + 1x2^0 = 32 + 16 + 0 + 4 + 0 + 1 = 53
Lecture 01 - Intro
Most Significant Digit - Least Significant Digit
Most Significant Digit (has weight of 2^5 or 32). For base 2, also called Most Significant Bit (MSB). Always LEFTMOST digit.
Least Significant Digit (has weight of 2^0 or 1). For base 2, also called Least Significant Bit (LSB). Always RIGHTMOST digit.
53 = % 110101
Lecture 01 - Intro
More Conversions
Convert 53 to Hex 53/16 = 3, rem = 5 3 /16 = 0 , rem = 3 53 = $ 35 = 3 x 16^1 + 5 x 16^0 = 48 + 5 = 53
Lecture 01 - Intro
Hex (base 16) to Binary Conversion
Each Hex digit represents 4 bits. To convert a Hex number to Binary, simply convert each Hex digit to its four bit value.
$ 9 = % 1001 $ A = % 1010 $ B = % 1011 $ C = % 1100 $ D = % 1101 $ E = % 1110 $ F = % 1111
$ A2F = % 1010 0010 1111 $ 345 = % 0011 0100 0101 Binary to Hex is just the opposite, create groups of 4 bits starting with least significant bits. If last group does not have 4 bits, then pad with zeros for unsigned numbers. % 1010001 = % 0101 0001 = $ 51 Padded with a zero
Lecture 01 - Intro
Binary to Decimal
If faced with a large binary number that has to be converted to decimal, I first convert the binary number to HEX, then convert the HEX to decimal. % 110111110011 = % 1101 1111 0011 = $ D F 3 = 13 x 16^2 + 15 x 16^1 + 3x16^0 = 13 x 256 + 15 x 16 + 3 x 1 = 3328 + 240 + 3 = 3571
Lecture 01 - Intro
Binary Codes • One Binary Digit (one bit) can take on values 0, 1. We can represent TWO values:
N bits (or N binary Digits) can represent 2^N different values. (for example, 4 bits can represent 2^4 or 16 different values) N bits can take on unsigned decimal values from 0 to 2N-1.
Codes usually given in tabular form.
000 black 001 red 010 pink 011 yellow 100 brown 101 blue 110 green 111 white
Lecture 01 - Intro
Binary Data cont’d
PC monitor screen can be configured for different resolutions. One resolution is 600 x 800 x 8, which means that you have 600 dots vertically x 800 dots horizontally, with each dot using 8 bits to take on 256 different colors. (a screen dot is called a pixel). Need 8 bits to represent 256 colors ( 28 = 256). Total number of bits needed to represent the screen is then: 600 x 800 x 8 = 3,840,000 bits (or just under 4 Mbits)
Your video card must have at least this much memory on it.
1 Mbits = 1024 x 1024 = 2^10 x 2^10 = 2^20 .
1 Kbits = 1024 = 2^10.
Lecture 01 - Intro
Codes for Characters Also need to represent Characters as digital data. The ASCII code (American Standard Code for Information Interchange) is a 7-bit code for Character data. Typically 8 bits are actually used with the 8th bit being zero or used for error detection (parity checking). 8 bits = 1 Byte.
‘A’ = % 01000001 = $41 ‘&’ = % 00100110 = $26
7 bits can only represent 2^7 different values (128). This enough to represent the Latin alphabet (A-Z, a-z, 0-9, punctuation marks, some symbols like $), but what about other symbols or other languages?
Lecture 01 - Intro
UNICODE UNICODE is a 16-bit code for representing alphanumeric data. With 16 bits, can represent 216 or 65536 different symbols. 16 bits = 2 Bytes per character. $0041-005A A-Z, $0061-007A a-z İ Capital dotted I =0304, I Lower dotless I = 0305, Ö Capital O umlaut = 0214, ö Lower O umlaut = 0246, Ü Capital U umlaut = 0220, ü Lower U umlaut = 0252, Ç Capital C cedille = 0199, ç Lower C cedille = 0231, Ğ Capital G breve = 0286, ğ Lower G breve = 0287, Ş Capital S cedille = 0350, ş Lower S cedille = 0351 UNICODE used by Web browsers, Java, and most of the software these days.
Lecture 01 - Intro
Codes for Decimal Digits
There are codes for representing decimal digits. These codes use 4-bits for EACH decimal digits; it is NOT the same as converting from decimal to binary. In BCD code, each decimal digit is simply represented by its binary equivalent. 96 = % 1001 0110 = $ 96 (BCD code) Advantage: easy to convert Disadvantage: takes more bits to store a number: 255 = % 1111 1111 = $ FF (binary code) 255 = % 0010 0101 0101 = $ 255 (BCD code) takes only 8 bits in binary, takes 12 bits in BCD.
A Gray code changes by only 1 bit for adjacent values. This is also called a ‘thumbwheel’ code because a thumbwheel for choosing a decimal digit can only change to an adjacent value (5 to 4 or 6, etc) with each click of the thumbwheel. This allows the binary output of the thumbwheel to only change one bit at a time; this can help reduce circuit complexity and also reduce signal noise.
Lecture 01 - Intro
Need to Know
• Convert hex, binary integers to Decimal • Convert decimal integers to hex, binary • Convert hex to binary, binary to Hex • N binary digits can represent 2N values, unsigned integers 0 to 2N-1. • ASCII, UNICODE are binary codes for character data • BCD code is alternate code for representing decimal digits • Gray codes can also represent decimal digits; adjacent values in Gray codes change only by one bit.
Lecture 02 – Number Systems
Binary Numbers
Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2N-1. 4 bits = 0 to 15 8 bits = 0 to 255 16 bits = 0 to 65535 Besides simply representation, we would like to also do arithmetic operations on numbers in binary form. Principle operations are addition and subtraction.
Lecture 02 – Number Systems
Binary Arithmetic, Subtraction The rules for binary arithmetic are: 0 + 0 = 0, carry = 0 1 + 0 = 1, carry = 0 0 + 1 = 1, carry = 0 1 + 1 = 0, carry = 1 The rules for binary subtraction are: 0 - 0 = 0, borrow = 0 1 - 0 = 1, borrow = 0 0 - 1 = 1, borrow = 1 1 - 1 = 0, borrow = 0 Borrows, Carries from digits to left of current of digit. Binary subtraction, addition works just the same as decimal addition, subtraction.
Lecture 02 – Number Systems
Binary, Decimal Addition
Decimal 34 + 17 ------ 51 from LSD to MSD: 7+4 = 1; with carry out of 1 to next column 1 (carry) + 3 + 1 = 5. answer = 51.
Why is $A + $8 = 2 with a carry out of 1? The carry out has a weight equal to the BASE (in this case 16). The digit that gets left is the excess (BASE - sum). $A + $8 = 10 + 8 = 18. 18 is GREATER than 16 (BASE), so need a carry out! Excess is 18 - BASE = 18 - 16 = 2, so ‘2’ is digit. Exactly the same thing happens in Decimal. 5 + 7 = 2, carry of 1. 5 + 7 = 12, this is greater than 10!. So excess is 12 - 10 = 2, carry of 1.
Lecture 02 – Number Systems
Hex Subtraction
$ 34 - $ 27 -------- $ 0D 4-7 = D; with borrow of 1 from next column 3 - 1 (borrow) - 2 = 0. answer = $ 0D.
Why is $4 - $7 = $D with a borrow of 1? The borrow has a weight equal to the BASE (in this case 16). BORROW +$4 - $7 = 16 + 4 -7 = 20 -7 = 13 = $D. $D is the result of the subtraction with the borrow. Exactly the same thing happens in decimal. 3 - 8 = 5 with borrow of 1 borrow + 3 - 8 = 10 + 3 - 8 = 13 - 8 = 5.
Lecture 02 – Number Systems
Fixed Precision With paper and pencil, you can write a number with as many digits as you want: 1,027,80,032,034,532,002,391,030,300,209,399,302,992,092,920 A microprocessor or computing system usually uses FIXED PRECISION for integers; they limit the numbers to a fixed number of bits: $ AF4500239DEFA231 64 bit number, 16 hex digits $ 9DEFA231 32 bit number, 8 hex digits $ A231 16 bit number, 4 hex digits $ 31 8 bit number, 2 hex digits High end microprocessors use 64 or 32 bit precision; low end microprocessors use 16 or 8 bit precision.
Lecture 02 – Number Systems
Unsigned Overflow
• In digital electronics we use 8 bit precision most of the time, 16 bit occassionally. • Overflow occurs when we add or subtract two numbers, and the correct result is a number that is outside of the range of allowable numbers for that precision. • We can have both unsigned and signed overflow (more on signed numbers later) 8 bits -- unsigned integers 0 to 28 -1 or 0 to 255. 16 bits -- unsigned integers 0 to 216-1 or 0 to 65535
Lecture 02 – Number Systems
Unsigned Overflow Example Assume 8 bit precision; ie. We can’t store any more than 8 bits for each number. Lets add 255 + 1 = 256. The number 256 is OUTSIDE the range of 0 to 255! What happens during the addition? 255 = $ FF + 1 = $ 01 ------------------- 256 /= $00 $F + 1 = 0, carry out $F + 1 (carry) + 0 = 0, carry out Carry out of MSB falls off end, No place to put it!!! Final answer is WRONG because could not store carry out. /= means Not Equal
Lecture 02 – Number Systems
Unsigned Overflow
A carry out of the Most Significant Digit (MSD) or Most Significant Bit (MSB) is an OVERFLOW indicator for addition of UNSIGNED numbers.
The correct result has overflowed the number range for that precision, and thus the result is incorrect.
If we could STORE the carry out of the MSD, then the answer would be correct. But we are assuming it is discarded because of fixed precision, so the bits we have left are the incorrect answer.
Lecture 02 – Number Systems
Signed Integer Representation
We have been ignoring large sets of numbers so far; ie. the sets of signed integers, fractional numbers, and floating point numbers.
We will not talk about fractional number representation (10.3456) or floating point representation (i.e. 9.23 x 1013).
We WILL talk about signed integer representation. The PROBLEM with signed integers ( - 45, + 27, -99) is the
SIGN. How do we encode the sign? The sign is an extra piece of information that has to be
encoded in addition to the magnitude.
Lecture 02 – Number Systems
Signed Magnitude Representatio
Signed Magnitude (SM) is a method for encoding signed
integers. The Most Significant Bit is used to represent the sign. ‘1’
is used for a ‘-’ (negative sign), a ‘0’ for a ‘+’ (positive sign).
The format of a SM number in 8 bits is: % smmmmmmm where ‘s’ is the sign bit and the other 7 bits represent the
magnitude. NOTE: for positive numbers, the result is the same as the
unsigned binary representation.
Lecture 02 – Number Systems
Signed Magnitude Examples (8 bits)
-5 = % 1 0000101 = $ 85 +5 = % 0 0000101 = $ 05 +127 = % 0 1111111 = $ 7F -127 = % 1 1111111 = $ FF + 0 = % 0 0000000 = $ 00 - 0 = % 1 0000000 = % 80 For 8 bits, can represent the signed integers -127 to +127. For N bits, can represent the signed integers -2(N-1) - 1 to + 2(N-1) - 1
Lecture 02 – Number Systems
Signed Magnitude comments
Signed magnitude easy to understand and encode. Is used today in some applications.
One problem is that it has two ways of representing 0 (-0, and +0) . Mathematically speaking, no such thing as two representations for zeros.
Another problem is that addition of K + (-K) does not give Zero!
-5 + 5 = $ 85 + $ 05 = $8A = -10 !!! Have to consider the sign when doing arithmetic for signed
magnitude representation.
Lecture 02 – Number Systems
Ones Complement Representation
Ones complement is another way to represent signed
integers. To encode a negative number, get the binary
representation of its magnitude, then COMPLEMENT each bit. Complementing each bit mean that 1s are replaced with 0s, 0s are replaced with 1s.
What is -5 in Ones Complement, 8 bits? The magnitude 5 in 8-bits is % 00000101 = $ 05 Now complement each bit: % 11111010 = $FA $FA is the 8-bit, ones complement number of -5. NOTE: positive numbers in 1s complement are simply their binary representation.
Lecture 02 – Number Systems
Ones Complement Examples
-5 = % 11111010 = $ FA +5 = % 00000101 = $ 05 +127 = % 01111111 = $ 7F -127 = % 10000000 = $ 80 + 0 = % 00000000 = $ 00 - 0 = % 11111111 = $ FF For 8 bits, can represent the signed integers -127 to +127. For N bits, can represent the signed integers -2(N-1) - 1 to + 2(N-1) - 1
Lecture 02 – Number Systems
Ones Complement Comments
Still have the problem that there are two ways of representing 0 (-0, and +0) . Mathematically speaking, no such thing as two representations for zeros.
However, addition of K + (-K) now gives Zero! -5 + 5 = $ FA + $ 05 = $FF = -0 !!! Unfortunately, K + 0 = K only works if we use +0,
does not work if we use -0. 5 + (+0) = $05 + $00 = $05 = 5 (ok) 5 + (-0) = $05 + $FF = $04 = 4 !!! (wrong)
Lecture 02 – Number Systems
Twos Complement Representation
Twos complement is another way to represent signed integers.
To encode a negative number, get the binary representation of its magnitude, COMPLEMENT each bit, then ADD 1. (get Ones complement, then add 1).
What is -5 in Twos Complement, 8 bits? The magnitude 5 in 8-bits is % 00000101 = $ 05 Now complement each bit: % 11111010 = $FA Now add one: $FA + 1 = $FB $FB is the 8-bit, twos complement representation of -5. NOTE: positive numbers in 2s complement are simply their
binary representation.
Lecture 02 – Number Systems
Twos Complement Examples
-5 = % 11111011 = $ FB +5 = % 00000101 = $ 05 +127 = % 01111111 = $ 7F -127 = % 10000001 = $ 81 -128 = % 10000000 = $80 (note the extended range!) + 0 = % 00000000 = $ 00 - 0 = % 00000000 = $ 00 (only 1 zero!!!) For 8 bits, can represent the signed integers -128 to +127. For N bits, can represent the signed integers -2(N-1) to + 2(N-1) - 1 Note that negative range extends one more than positive
range.
Lecture 02 – Number Systems
Twos Complement Comments
Twos complement is the method of choice for representing signed integers.
It has none of the drawbacks of Signed Magnitude or Ones Complement.
There is only one zero, and K + (-K) = 0. -5 + 5 = $ FB + $ 05 = $00 = 0 !!! Normal binary addition is used for adding numbers
that represent twos complement integers.
Lecture 02 – Number Systems
Example Conversions
$FE as an 8 bit unsigned integer = 254 $FE as an 8 bit signed magnitude integer = -126 $FE as an 8 bit ones complement integer = - 1 $FE as an 8 bit twos complement integer = -2 $7F as an 8 bit unsigned integer = 127 $7F as an 8 bit signed magnitude integer = +127 $7F as an 8 bit ones complement integer = +127 $7f as an 8 bit twos complement integer = +127 To do hex to signed decimal conversion, we need to
Given a Hex number, and you are told to convert to a
signed integer (either as signed magnitude, 1s complement, 2s complement)
STEP 1: Determine the sign! If the Most Significant Bit is zero, the sign is positive. If the MSB is one, the sign is negative. This is true for ALL THREE representations: SM, 1s complement, 2s complement.
$F0 = % 11110000 (MSB is ‘1’), so sign of result is ‘-’ $64 = % 01100100 (MSB is ‘0’), so sign of result is ‘+’. If the Most Significant Hex Digit is > 7, then MSB = ‘1’ !!! (eg, $8,9,A,B,C,D,E,F => MSB = ‘1’ !!!)
Lecture 02 – Number Systems
Hex to Signed Decimal (cont)
STEP 2 (positive sign): If the sign is POSITIVE, then just convert the hex value to decimal. The representation is the same for SM, 1s complement, 2s complement.
$64 is a positive number, decimal value is 6 x 16 + 4 = 100. Final answer is +100 regardless of whether encoding was
SM, 1s complement, or 2s complement. $64 as an 8 bit signed magnitude integer = +100 $64 as an 8 bit ones complement integer = +100 $64 as an 8 bit twos complement integer = +100
Lecture 02 – Number Systems
Hex to Signed Decimal (cont)
STEP 2 (negative sign): If the sign is Negative, then need to compute the magnitude of the number.
We will use the trick that - (-N) = + N i.e. Take the negative of a negative number will give you
the positive number. In this case the number will be the magnitude.
If the number is SM format, set Sign bit to Zero: $F0 = % 11110000 => % 01110000 = $70 = 112 If the number is 1s complement, complement each bit. $F0 = % 11110000 => % 00001111 = $0F = 15 If the number is 2s complement, complement and add one. $F0 = % 11110000 => %00001111 + 1 = %00010000 =
$10 = 16
Lecture 02 – Number Systems
Hex to Signed Decimal (cont)
STEP 3 : Just combine the sign and magnitude to get the result.
$F0 as 8 bit Signed magnitude number is -112 $F0 as 8 bit ones complement number is -15 $F0 as 8 bit twos complement number is -16 $64 as an 8 bit signed magnitude integer = +100 $64 as an 8 bit ones complement integer = +100 $64 as an 8 bit twos complement integer = +100
Lecture 02 – Number Systems
Signed Decimal to Hex conversion
Step 1: Know what format you are converting to!!! You must
know if you are converting the signed decimal to SM, 1s complement, or 2s complement.
Convert +34 to all three formats. Convert -20 to all three formats Step 2: Ignore the sign, convert the magnitude of the
number to binary. 34 = 2 x 16 + 2 = $ 22 = % 00100010 20 = 1 x 16 + 4 = $ 14 = % 00010100
Lecture 02 – Number Systems
Signed Decimal to Hex conversion (cont)
Step 3 (positive decimal number): If the decimal number was positive, then you are finished no matter what the format is!
+34 as an 8 bit SM number is $ 22 = % 00100010 +34 as an 8 bit 1s complement number is $ 22 = %
00100010 +34 as an 8 bit 2s complement number is $ 22 = %
00100010
Lecture 02 – Number Systems
Signed Decimal to Hex conversion (cont)
Step 3 (negative decimal number): Need to do more if decimal number was negative. To get the final representation, we will use the trick that:
- (+N) = -N i.e., if you take the negative of a positive number, get
Negative number. If converting to SM format, set Sign bit to One: 20 = % 00010100 => % 10010100 = $94 If converting to 1s complement, complement each bit. 20 = % 00010100 => % 11101011 = $EB If converting to 2s complement, complement and add one. 20 = % 00010100 => %11101011 + 1 = %11101100 = $EC
Lecture 02 – Number Systems
Signed Decimal to Hex conversion (cont)
Final results: +34 as an 8 bit SM number is $ 22 = % 00100010 +34 as an 8 bit 1s complement number is $ 22 = %
00100010 +34 as an 8 bit 2s complement number is $ 22 = %
00100010 -20 as an 8 bit SM number is $ 94 = % 10010100 -20 as an 8 bit 1s complement number is $ EB = %
11101011 -20 as an 8 bit 2s complement number is $ EC = %
11101100
Lecture 02 – Number Systems
Two’s Complement Overflow
Consider two 8-bit 2’s complement numbers. We can represent the signed integers -128 to +127 using this representation.
What if we do (+1) + (+127) = +128. The number +128 is OUT of the RANGE that we can represent with 8 bits. What happens when we do the binary addition? +127 = $ 7F + +1 = $ 01 ------------------- 128 /= $80 (this is actually -128 as a twos complement
number!!! - the wrong answer!!!) How do we know if overflowed occurred? Added two POSITIVE numbers, and got a NEGATIVE result.
Lecture 02 – Number Systems
Detecting Two’s Complement Overflow
Two’s complement overflow occurs if: Add two POSITIVE numbers and get a NEGATIVE result Add two NEGATIVE numbers and get a POSITIVE result We CANNOT get two’s complement overflow if we add a
NEGATIVE and a POSITIVE number together. The Carry out of the Most Significant Bit means nothing if
the numbers are two’s complement numbers.
Lecture 02 – Number Systems
Some Examples
All hex numbers represent signed decimal in two’s complement format. $ FF = -1 + $ 01 = + 1 -------- $ 00 = 0 Note there is a carry out, but the answer is correct. Can’t have 2’s
complement overflow when adding positive and negative number. $ FF = -1 + $ 80 = -128 -------- $ 7F = +127 (incorrect!!) Added two negative numbers, got a positive number. Twos
Complement overflow.
Lecture 02 – Number Systems
Adding Precision (unsigned)
What if we want to take an unsigned number and add more bits to it?
Just add zeros to the left. 128 = $80 (8 bits) = $0080 (16 bits) = $00000080 (32 bits)
Lecture 02 – Number Systems
Adding Precision (two’s complement)
What if we want to take a twos complement number and
add more bits to it? Take whatever the SIGN BIT is, and extend it to the left.
-128 = $80 = % 10000000 (8 bits) = $FF80 = % 1111111110000000 (16 bits) = $FFFFFF80 (32 bits) + 127 = $7F = % 01111111 (8 bits) = $007F = % 0000000001111111 ( 16 bits) = $0000007F (32 bits) This is called SIGN EXTENSION. Extending the MSB to
the left works for two’s complement numbers and unsigned numbers.
Lecture 02 – Number Systems
Need to Know
• Addition, subtraction of binary, hex numbers • Detecting unsigned overflow • Converting a decimal number to Signed magnitude, Ones Complement, Twos Complement • Converting a hex number in either SM, 1s complement, 2s complement to decimal • Number ranges for unsigned, SM, 1s complement, 2s complement • Overflow in 2s complement • Sign extension in 2s complement
Lecture 03 – Boolean Algebra
Boolean Algebra
• Algebra: – Formal mathematical system with a set of objects
and operations on those objects – Examples; Numerical algebra, set algebra, and
Boolean Algebra • Boolean Algebra
– Invented by George Bool, (1815-1864) mathematician & philosopher
Lecture 03 – Boolean Algebra
Boolean Algebra
• Is the algebra of logic • A way to express logic functions with logic
equations. • Extensively used in electronic circuits to build
computers and other logic circuits • Can be used to analyze and describe the
behavior of logic circuits.
Lecture 03 – Boolean Algebra
Elements of Boolean algebra
• Variables • Values • Operations
– AND, OR, NOT • Laws
– a + 1 = 1 – A * 0 = 0 – Not (Not (a)) = a – . . .
Lecture 03 – Boolean Algebra
Variables & Values
• Variables – Usually given the names
• a, b, c, . .
– Should be of Boolean type – Can change values over time
• Values • Domain: 0 and 1 (True & False)
Lecture 03 – Boolean Algebra
Operators
• AND, OR, NOT
• Both AND and OR are binary, commutative and associative operators
• The NOT operator is unary
• Follow fixed priority (precedence) scheme
Lecture 03 – Boolean Algebra
Operators Precedence
• To determine order of evaluation • To override the given precedence, use
parentheses 1. NOT
• Negation/inversion • Represented by: ' , ! (in C-Language), ~, , or ¬
2. AND • Logical product • Represented by: • , *, && (in C-Language), or ^
3. OR • Logical sum • Represented by: + , | | (in C-Language), or v
Lecture 03 – Boolean Algebra
Operators Precedence
• Example: • Evaluate: X + Y • ! Z ' • Order used: ( X + (Y • (Z ')))
• First negate Z • Then AND with Y • Then OR with x
Lecture 03 – Boolean Algebra
Boolean Functions • Logic functions are written as a series of
equations with an output on the left-hand side of each equation and a formula consisting of variables combined with the logical operators on the right-hand side.
• Boolean function – A specific boolean expression – Usually given the name F with a possible subscript – Has a number of input variables – Has a unique output value. – Can be described by either a truth table or by an
algebraic description. – Two functions are the same if the truth tables are the
same
Lecture 03 – Boolean Algebra
Boolean Functions • Function as an algebraic expression
– Example: • F (x, y, z) = x • y + z • Simply F = x • y + z
• Function as a truth table – Example:
X Y Z X • Y X • Y + Z (F)
0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 0 1
1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1
Lecture 03 – Boolean Algebra
Boolean Functions • Examples:
– X = A AND B – Meaning:
• X is true ⇔ (if and only if) both A and B are true – X = A OR B AND NOT C – Meaning:
• X is true ⇔ Either A is true or B is true and C is false
Lecture 03 – Boolean Algebra
Some Definitions • Boolean expression:
– A sequence of zeros, ones, and literals separated by boolean operators • Literal:
– A variable or a complement of a variable. – Examples: A, B, A', B'
• Product Term – A single literal or a logical product (AND) of two or more literals. – Examples:
• A' • A• B'• C
• Sum Term – A single literal or a logical sum (OR) of two or more literals. – Examples:
• A' • A + B + C • A + B' + C'
Lecture 03 – Boolean Algebra
More Definitions • Product-of-sums :
– A logical product (AND) of Sum Terms. – Example:
• A' • (A + B + C) • (A + B' + C) • (A' + B' + C)
• Sum-of product : – A logical sum (OR) of Product Terms. – Example:
• A' + (A • B • C) + (A • B' • C) + (A' • B' • C)
Lecture 03 – Boolean Algebra
More Definitions • Normal term:
– A Product (or Sum) term in which no variable appears more than once.
• n-variable Minterm: – A normal Product term with n-literals in which all variables appear
exactly once, either complemented or un-complemented – There are 2n such product terms.
• n-variable Maxterm: – A normal Sum term with n-literals in which all variables appear exactly
once, either complemented or un-complemented – There are 2n such sum terms.
Lecture 03 – Boolean Algebra
Minterm / Maxterm Examples • Normal term Examples:
– A • B • C' Normal term – A • B • B • C' Non-normal term
• 4-variable Minterm: – A • B • C • D – A • B' • C • D – A • B • C' • D' – A' • B' • C' • D'
• 4-variable Maxterm: – A + B + C+ D – A' + B' + C+ D – A + B + C'+ D' – A' + B' + C'+ D'
Lecture 03 – Boolean Algebra
Are Boolean Functions Useful?
• Having all the elements of an algebra (values, variables, and operators), we can use these elements to derive a series of useful laws – Find equivalent functions – Simplify a given function
• Might provide for more efficient or cheaper circuit design
Lecture 03 – Boolean Algebra
Laws of Boolean Algebra • Single-Variable Theorems
1. Identity A + 0 = A A • 1 = A
2. Dominance A + 1 = 1 A • 0 = 0
3. Idempotent A • A = A A + A = A
4. Inverse (Complement) A + A' = 1 A • A' = 0
5. Involution (Law of the double complement) (A') ' = A
Lecture 03 – Boolean Algebra
Laws of Boolean Algebra
• Two and Three Variable Theorems 6. Commutative
A + B = B + A A • B = B • A
7. Associative A + (B + C) = (A + B) + C A • (B • C) = (A • B) • C
8. Distributive A • (B + C) = (A • B) + (A • C) A + (B • C) = (A + B) • (A + C)
9. Covering (Absorption / Redundance) A + A • B = A A • ( A + B ) = A A + A' • B = A + B A • (A' + B) = A • B
Lecture 03 – Boolean Algebra
Laws of Boolean Algebra
• Two and Three Variable Theorems 10. Combining
A • B + A • B' = A
(A + B) • (A + B' ) = A
11. Consensus A • B + A' • C + B • C = A • B + A' • C
(A + B) • (A' + C) • (B + C) = (A + B) • (A' + C)
12. Common identities ??? A + A' • B = A + B
A • (A' + B) = A • B
Lecture 03 – Boolean Algebra
Laws of Boolean Algebra
• The most useful theorems 13. DeMorgan's
(A + B)' = A' • B' (NOR)
(A • B)' = A' + B' (NAND)
• DeMorgan's theorems apply to more than 2 variables
Lecture 03 – Boolean Algebra
Laws of Boolean Algebra
• You can check the correction of the above theorems by either of the following:
1. Building their equivalent logic circuits & checking the o/p of the circuit for all i/p combinations
2. Building the truth table of the function
3. Using Venn diagrams (Suitable for up to 3 variables)
4. By derivation – successive application of other laws
Lecture 03 – Boolean Algebra
Duality principle
• All laws of Boolean algebra are stated in pairs
• They are obtained by: – swapping 0's and 1's, and
– swapping +'s with •'s
Lecture 03 – Boolean Algebra
Examples • Applying DeMorgan's
X = ( ( A' + C) • ( B + D' ) ) ' = ( A' + C ) ' + ( B + D' ) ' By DeMorgan's = ( A ' ' • C ' ) + ( B ' • D ' ' ) By DeMorgan's = A • C ' + B ' • D
• Applying other laws X = A' • B • C + A' • B • C'
= A' • (B • C + B • C') By Distributive
= A' • (B • ( C + C')) By Distributive
= A' • (B • 1) By Inverse = A' • B By Identity
Lecture 03 – Boolean Algebra
Truth Tables
• Completely describe any combinational logic function • Describe the output with respect to the input • Each entry specifies the value of the output for that
particular input combination • Each output column represents a different function • Functions may be directly constructed from the truth
table • For a function with n-inputs, there is 2 n entries in the
truth table
Lecture 03 – Boolean Algebra
Truth Tables
• Example: Inputs
A B C Outputs
D E F
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
0 0 0
1 0 0
1 0 0
1 1 0
1 0 0
1 1 0
1 0 1
0 1 1
Lecture 03 – Boolean Algebra
Deriving Functions From Truth Tables
• For each place where output is 1 – Create an AND expression of the inputs
– If input is 0, negate its value – Else, just use the variable name
– OR all the expressions together
A B Output(C) 0 0 1 0 1 0 1 0 1 1 1 0
C = AB + AB
Lecture 03 – Boolean Algebra
Deriving Functions From Truth Tables
• Exercise: – Write the functions for Sum and Carry – Hint: This is the function for addition
This process is continued until we finally obtain an. Note that the remainderobtained at each division step is one of the desired digits and the least significantdigit is obtained first.
Convert 5310 to binary.Example
2
2 rem. ! 1 ! a0
2 rem. ! 0 ! a1
2 rem. ! 1 ! a2 5310 ! 1101012
2 rem. ! 0 ! a3
2 rem. ! 1 ! a4
0 rem. ! 1 ! a5
Conversion of a decimal fraction to base R can be done using successive multi-plications by R. A decimal fraction F can be represented as
where F1 represents the fractional part of the result and a"1 is the integer part.Multiplying F1 by R yields
F1R ! a"2 # a"3R"1 # · · · # a"mR"m#2 ! a"2 # F2
!1
!3
!6
!13
!26
!53
Q2
R
Q1
R
NR
10 Unit 1
Next, we multiply F2 by R:
F2R ! a"3 # · · · # a"mR"m#3 ! a"3 # F3
This process is continued until we have obtained a sufficient number of digits. Notethat the integer part obtained at each step is one of the desired digits and the mostsignificant digit is obtained first.
Convert 0.62510 to binary.Example
F ! .625 F1 ! .250 F2 ! .500$ 2 $ 2 $ 2 .62510 ! .1012
1.250 0.500 1.000(a"1 ! 1) (a"2 ! 0) (a"3 ! 1)
This process does not always terminate, but if it does not terminate, the result isa repeating fraction.
Convert 0.710 to binary.Example
.72
(1).42
(0).82
(1).62
(1).22
(0).4 !" process starts repeating here because 0.4 was previously2 obtained
(0).8 0.710 ! 0.1 0110 0110 0110 . . . 2
Conversion between two bases other than decimal can be done directly by usingthe procedures given; however, the arithmetic operations would have to be carriedout using a base other than 10. It is generally easier to convert to decimal first andthen convert the decimal number to the new base.
Number Systems and Conversion 11
Add 1310 and 1110 in binary.Example
1 1 1 1 !" carries1310 ! 11011110 ! 1011
11000 ! 2410
The subtraction table for binary numbers is
0 " 0 ! 00 " 1 ! 1 and borrow 1 from the next column1 " 0 ! 11 " 1 ! 0
Borrowing 1 from a column is equivalent to subtracting 1 from that column.
"10011 from the " 11 " 10111010 3rd column) 1101 101110
Note how the borrow propagates from column to column in the second exam-ple. In order to borrow 1 from the second column, we must in turn borrow 1 fromthe third column, etc. An alternative to binary subtraction is the use of 2’s comple-ment arithmetic, as discussed in Section 1.4.
Binary subtraction sometimes causes confusion, perhaps because we are so usedto doing decimal subtraction that we forget the significance of the borrowingprocess. Before doing a detailed analysis of binary subtraction, we will review theborrowing process for decimal subtraction.
If we number the columns (digits) of a decimal integer from right toleft (starting with 0), and then we borrow 1 from column n, what we mean is thatwe subtract 1 from column n and add 10 to column n " 1. Because 1 # 10n !10 # 10n"1, the value of the decimal number is unchanged, but we can proceedwith the subtraction. Consider, for example, the following decimal subtractionproblem:
column 2 column 1
205" 18
187
Number Systems and Conversion 13!!"
Examplesof Binary
Subtraction
1.3 Convert to base 6: 3BA.2514 (do all of the arithmetic in decimal).
1.4 (a) Convert to hexadecimal: 1457.1110. Round to two digits past the hexadecimal point.(b) Convert your answer to binary, and then to octal.(c) Devise a scheme for converting hexadecimal directly to base 4 and convert your
answer to base 4.(d) Convert to decimal: DEC.A16.
1.5 Add, subtract, and multiply in binary:(a) 1111 and 1010 (b) 110110 and 11101 (c) 100100 and 10110
1.6 Subtract in binary. Place a 1 over each column from which it was necessary to borrow.(a) 11110100 ! 1000111 (b) 1110110 ! 111101 (c) 10110010 ! 111101
1.7 Add the following numbers in binary using 2’s complement to represent negative num-bers. Use a word length of 6 bits (including sign) and indicate if an overflow occurs.(a) 21 " 11 (b) (!14) " (!32) (c) (!25) " 18(d) (!12) " 13 (e) (!11) " (!21)Repeat (a), (c), (d), and (e) using 1’s complement to represent negative numbers.
1.8 A computer has a word length of 8 bits (including sign). If 2’s complement is used torepresent negative numbers, what range of integers can be stored in the computer?If 1’s complement is used? (Express your answers in decimal.)
1.9 Construct a table for 7-3-2-1 weighted code and write 3659 using this code.
1.10 Convert to hexadecimal and then to binary.(a) 1305.37510 (b) 111.3310 (c) 301.1210 (d) 1644.87510
1.11 Convert to octal. Convert to hexadecimal. Then convert both of your answers todecimal, and verify that they are the same.(a) 101111010100.1012 (b) 100001101111.012
1.12 (a) Convert to base 3: 375.548 (do all of the arithmetic in decimal).(b) Convert to base 4: 384.7410.(c) Convert to base 9: A52.A411 (do all of the arithmetic in decimal).
1.13 Convert to hexadecimal and then to binary: 544.19.
1.14 Convert the decimal number 97.710 into a number with exactly the same value rep-resented in the following bases. The exact value requires an infinite repeating partin the fractional part of the number. Show the steps of your derivation.(a) binary (b) octal (c) hexadecimal (d) base 3 (e) base 5
1.15 Devise a scheme for converting base 3 numbers directly to base 9. Use your methodto convert the following number to base 9: 1110212.202113
24 Unit 1
1.3 Convert to base 6: 3BA.2514 (do all of the arithmetic in decimal).
1.4 (a) Convert to hexadecimal: 1457.1110. Round to two digits past the hexadecimal point.(b) Convert your answer to binary, and then to octal.(c) Devise a scheme for converting hexadecimal directly to base 4 and convert your
answer to base 4.(d) Convert to decimal: DEC.A16.
1.5 Add, subtract, and multiply in binary:(a) 1111 and 1010 (b) 110110 and 11101 (c) 100100 and 10110
1.6 Subtract in binary. Place a 1 over each column from which it was necessary to borrow.(a) 11110100 ! 1000111 (b) 1110110 ! 111101 (c) 10110010 ! 111101
1.7 Add the following numbers in binary using 2’s complement to represent negative num-bers. Use a word length of 6 bits (including sign) and indicate if an overflow occurs.(a) 21 " 11 (b) (!14) " (!32) (c) (!25) " 18(d) (!12) " 13 (e) (!11) " (!21)Repeat (a), (c), (d), and (e) using 1’s complement to represent negative numbers.
1.8 A computer has a word length of 8 bits (including sign). If 2’s complement is used torepresent negative numbers, what range of integers can be stored in the computer?If 1’s complement is used? (Express your answers in decimal.)
1.9 Construct a table for 7-3-2-1 weighted code and write 3659 using this code.
1.10 Convert to hexadecimal and then to binary.(a) 1305.37510 (b) 111.3310 (c) 301.1210 (d) 1644.87510
1.11 Convert to octal. Convert to hexadecimal. Then convert both of your answers todecimal, and verify that they are the same.(a) 101111010100.1012 (b) 100001101111.012
1.12 (a) Convert to base 3: 375.548 (do all of the arithmetic in decimal).(b) Convert to base 4: 384.7410.(c) Convert to base 9: A52.A411 (do all of the arithmetic in decimal).
1.13 Convert to hexadecimal and then to binary: 544.19.
1.14 Convert the decimal number 97.710 into a number with exactly the same value rep-resented in the following bases. The exact value requires an infinite repeating partin the fractional part of the number. Show the steps of your derivation.(a) binary (b) octal (c) hexadecimal (d) base 3 (e) base 5
1.15 Devise a scheme for converting base 3 numbers directly to base 9. Use your methodto convert the following number to base 9: 1110212.202113