Upload
air-university-multan
View
175
Download
1
Embed Size (px)
Citation preview
1
INTRODUCTION
Zubair saif
DIGIAL LOGIC & DESIGN(EE-204)
Overview
Digital Systems, Computers, and BeyondInformation RepresentationNumber Systems [binary, octal and
hexadecimal]Arithmetic OperationsBase ConversionDecimal CodesAlphanumeric CodesParity BitGray Codes
DIGITAL & COMPUTER SYSTEMS - Digital System
Takes a set of discrete information inputs and discrete internal information (system state) and generates a set of discrete information outputs.
System State
DiscreteInformationProcessingSystem
DiscreteInputs Discrete
Outputs
Types of Digital Systems
No state present Combinational Logic System Output = Function(Input)
State present State updated at discrete times
Synchronous Sequential System State updated at any time
Asynchronous Sequential System State = Function (State, Input) Output = Function (State) or Function
(State, Input)
Digital System Example
A Digital Counter (e. g., odometer)
1 30 0 5 6 4Count Up
Reset
Inputs: Count Up, Reset
Outputs: Visual Display
State: "Value" of stored digits
Digital Computer Example
Inputs: keyboard, mouse, wireless, microphone
Outputs: LCD screen, wireless, speakers
Memory
Controlunit Datapath
Input/Output
CPU
And Beyond – Embedded Systems
Chapter 1 8
Computers as integral parts of other productsExamples of embedded computers
Microcomputers Microcontrollers Digital signal processors
Examples of Embedded Systems Applications Cell phones Automobiles Video games Copiers Dishwashers Flat Panel TVs Global Positioning Systems
INFORMATION REPRESENTATION - Signals
Chapter 1 9
Information variables represented by physical quantities.
For digital systems, the variables take on discrete values.
Two level, or binary values are the most prevalent values in digital systems.
Binary values are represented abstractly by: digits 0 and 1 words (symbols) False (F) and True (T) words (symbols) Low (L) and High (H) and words On and Off.
Binary values are represented by values or ranges of values of physical quantities
Signal Examples Over Time
Chapter 1 10
Analog
Asynchronous
Synchronous
Time
Continuous in value &
time
Discrete in value & continuous
in time
Discrete in value &
time
Digital
NUMBER SYSTEMS – Representation
Chapter 1 11
Positive radix, positional number systemsA 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
Number Systems – Examples
Chapter 1 12
General Decimal Binary
Radix (Base) r 10 2
Digits 0 => r - 1 0 => 9 0 => 1
0123
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
110
1001000
10,000100,000
0.10.01
0.0010.0001
0.00001
124816320.50.25
0.1250.0625
0.03125
Decimal Number System13 / 45
Base (also called radix) = 10 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
Digit Position Integer & fraction
Digit Weight Weight = (Base) Position
Magnitude Sum of “Digit x Weight”
Formal Notation
1 0 -12 -2
5 1 2 7 4
10 1 0.1100 0.01
500 10 2 0.7
0.04
d2*B2+d1*B1+d0*B0+d-1*B-1+d-
2*B-2
(512.74)1
0
Octal Number System14 / 45
Base = 8 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
Weights Weight = (Base) Position
Magnitude Sum of “Digit x Weight”
Formal Notation
1 0 -12 -2
8 1 1/864 1/64
5 1 2 7 4
5 *82+1 *81+2 *80+7 *8-
1+4 *8-2
=(330.9375)10
(512.74)8
Binary Number System15 / 45Base = 2
2 digits { 0, 1 }, called binary digits or “bits”
Weights Weight = (Base) Position
Magnitude Sum of “Bit x Weight”
Formal NotationGroups of bits 4 bits = Nibble
8 bits = Byte
1 0 -12 -2
2 1 1/24 1/4
1 0 1 0 1
1 *22+0 *21+1 *20+0 *2-
1+1 *2-2
=(5.25)10
(101.01)2
1 0 1 1
1 1 0 0 0 1 0 1
Hexadecimal Number System16 / 45Base = 16
16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }Weights
Weight = (Base) Position
Magnitude Sum of “Digit x Weight”
Formal Notation
1 0 -12 -2
16 1 1/16256 1/256
1 E 5 7 A
1 *162+14 *161+5 *160+7 *16-
1+10 *16-2
=(485.4765625)10
(1E5.7A)16
The Power of 217 / 45
n 2n
0 20=1
1 21=2
2 22=4
3 23=8
4 24=16
5 25=32
6 26=64
7 27=128
n 2n
8 28=256
9 29=512
10 210=1024
11 211=2048
12 212=4096
20 220=1M
30 230=1G
40 240=1T
Mega
Giga
Tera
Kilo
Addition18 / 45
Decimal Addition
5 5
55+
011
= Ten ≥ Base Subtract a Base
11 Carry
Binary Addition19 / 45
Column Addition
1 0 1111
1111 0+
0000 1 11
≥ (2)10
111111= 61
= 23
= 84
Binary Subtraction20 / 45Borrow a “Base” when needed
0 0 1110
1111 0−
0101 1 10
= (10)2
2
2
2 2
1
000
1
= 77
= 23
= 54
Binary Multiplication21 / 45Bit by bit
01 1 1 1
01 1 0
00 0 0 0
01 1 1 1
01 1 1 1
0 0 000
0110111 0
x
Number Base Conversions22 / 45
Decimal(Base 10)
Octal(Base 8)
Binary(Base 2)
Hexadecimal(Base 16)
Evaluate Magnitude
Evaluate Magnitude
Evaluate Magnitude
Decimal (Integer) to Binary Conversion23 / 45
Divide the number by the ‘Base’ (=2)Take the remainder (either 0 or 1) as a coefficientTake the quotient and repeat the division
Example: (13)10
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2
MSB LSB
Quotient Remainder Coefficient
13/ 2 = 6 1 a0 = 1 6 / 2 = 3 0 a1 = 0 3 / 2 = 1 1 a2 = 1 1 / 2 = 0 1 a3 = 1
Decimal (Fraction) to Binary Conversion24 / 45
Multiply the number by the ‘Base’ (=2)Take the integer (either 0 or 1) as a coefficientTake the resultant fraction and repeat the division
Example: (0.625)10
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2
MSB LSB
Integer Fraction Coefficient
0.625× 2 = 1 . 250.25 × 2 = 0 . 5 a-2 = 00.5 × 2 = 1 . 0 a-3 = 1
a-1 = 1
Decimal to Octal Conversion25 / 45Example: (175)10
Quotient Remainder Coefficient
Answer: (175)10 = (a2 a1 a0)8 = (257)8
175 / 8 = 21 7 a0 = 7 21 / 8 = 2 5 a1 = 5 2 / 8 = 0 2 a2 = 2
Example: (0.3125)10
Integer Fraction Coefficient
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
0.3125* 8 = 2 . 50.5 * 8 = 4 . 0 a-2 = 4
a-1 = 2
Binary − Octal Conversion26 / 458 = 23
Each group of 3 bits represents an octal digit
Octal Binary
0 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
Example:
( 1 0 1 1 0 . 0 1 )2
( 2 6 . 2 )8
Assume Zeros
Works both ways (Binary to Octal & Octal to Binary)
Binary − Hexadecimal Conversion27 / 4516 = 24
Each group of 4 bits represents a hexadecimal digit
Hex Binary0 0 0 0 01 0 0 0 12 0 0 1 03 0 0 1 14 0 1 0 05 0 1 0 16 0 1 1 07 0 1 1 18 1 0 0 09 1 0 0 1A 1 0 1 0B 1 0 1 1C 1 1 0 0D 1 1 0 1E 1 1 1 0F 1 1 1 1
Example:
( 1 0 1 1 0 . 0 1 )2
( 1 6 . 4 )16
Assume Zeros
Works both ways (Binary to Hex & Hex to Binary)
Octal − Hexadecimal Conversion28 / 45
Example:
( 0 1 0 1 1 0 . 0 1 0 )2
( 1 6 . 4 )16
Assume Zeros
Works both ways (Octal to Hex & Hex to Octal)
( 2 6 . 2 )8
Assume Zeros
Decimal, Binary, Octal and Hexadecimal29 / 45
Decimal Binary Octal Hex00 0000 00 001 0001 01 102 0010 02 203 0011 03 304 0100 04 405 0101 05 506 0110 06 607 0111 07 708 1000 10 809 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F
Complements30 / 45
1’s Complement (Diminished Radix Complement) All ‘0’s become ‘1’s All ‘1’s become ‘0’sExample (10110000)2
(01001111)2
If you add a number and its 1’s complement …
1 0 1 1 0 0 0 0+ 0 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1
Complements31 / 45
2’s Complement (Radix Complement) Take 1’s complement then add 1 Toggle all bits to the left of the first ‘1’ from the
rightExample:Number:1’s Comp.:
0 1 0 1 0 0 0 0
1 0 1 1 0 0 0 00 1 0 0 1 1 1 1
+ 1
OR
1 0 1 1 0 0 0 0
00001010
Negative Numbers32 / 45
Computers Represent Information in ‘0’s and ‘1’s ‘+’ and ‘−’ signs have to be represented in ‘0’s and
‘1’s3 Systems
Signed Magnitude 1’s Complement 2’s ComplementAll three use the left-most bit to represent the sign:
‘0’ positive ‘1’ negative
Signed Magnitude Representation33 / 45Magnitude is magnitude, does not change
with sign
(+3)10 ( 0 0 1 1 )2
(−3)10 ( 1 0 1 1 )2
Can’t include the sign bit in ‘Addition’
0 0 1 1 (+3)10
+ 1 0 1 1 (−3)10
1 1 1 0 (−6)10
Sign Magnitude
S Magnitude (Binary)
1’s Complement Representation34 / 45
Positive numbers are represented in “Binary”
Negative numbers are represented in “1’s Comp.”
(+3)10 (0 011)2
(−3)10 (1 100)2
There are 2 representations for ‘0’(+0)10 (0 000)2
(−0)10 (1 111)2
0 Magnitude (Binary)
1Code (1’s Comp.)
1’s Complement Range35 / 45
4-Bit Representation
24 = 16 Combinations − 7 ≤ Number ≤ + 7
−23+1 ≤ Number ≤ +23 − 1n-Bit Representation
−2n−1+1 ≤ Number ≤ +2n−1 − 1
Decimal 1’s Comp.+ 7 0 1 1 1+ 6 0 1 1 0+ 5 0 1 0 1+ 4 0 1 0 0+ 3 0 0 1 1+ 2 0 0 1 0+ 1 0 0 0 1+ 0 0 0 0 0− 0 1 1 1 1− 1 1 1 1 0− 2 1 1 0 1− 3 1 1 0 0− 4 1 0 1 1− 5 1 0 1 0− 6 1 0 0 1− 7 1 0 0 0
2’s Complement Representation36 / 45Positive numbers are represented in
“Binary”
Negative numbers are represented in “2’s Comp.”
(+3)10 (0 011)2
(−3)10 (1 101)2
There is 1 representation for ‘0’(+0)10 (0 000)2
(−0)10 (0 000)2
0 Magnitude (Binary)
1 Code (2’s Comp.)
1’s Comp. 1 1 1 1 + 1 1 0 0 0 0
2’s Complement Range37 / 45
4-Bit Representation
24 = 16 Combinations − 8 ≤ Number ≤ + 7
−23 ≤ Number ≤ + 23 − 1n-Bit Representation
−2n−1 ≤ Number ≤ + 2n−1 − 1
Decimal 2’s Comp.+ 7 0 1 1 1+ 6 0 1 1 0+ 5 0 1 0 1+ 4 0 1 0 0+ 3 0 0 1 1+ 2 0 0 1 0+ 1 0 0 0 1+ 0 0 0 0 0− 1 1 1 1 1− 2 1 1 1 0− 3 1 1 0 1− 4 1 1 0 0− 5 1 0 1 1− 6 1 0 1 0− 7 1 0 0 1− 8 1 0 0 0
Number Representations38 / 45
4-Bit Example
Unsigned Binary
Signed Magnitude 1’s Comp. 2’s Comp.
Range 0 ≤ N ≤ 15 -7 ≤ N ≤ +7 -7 ≤ N ≤ +7 -8 ≤ N ≤ +7
Positive
Binary Binary Binary Binary
Negative XBinary 1’s Comp. 2’s Comp.
0 0 0
1 1 1
Binary Subtraction Using 1’s Comp. Addition
39 / 45
Change “Subtraction” to “Addition”If “Carry” = 1
then add it to theLSB, and the resultis positive(in Binary)
If “Carry” = 0then the resultis negative(in 1’s Comp.)
0 1 0 1
+ 1 1 1 0
(5)10 – (1)10
(+5)10 + (-1)10
0 0 1 1+
0 1 0 0
0 1 0 1
+ 1 0 0 1
(5)10 – (6)10
(+5)10 + (-6)10
0 1 1 1 0
1 1 1 0
+ 4 − 1
1
Binary Subtraction Using 2’s Comp. Addition40 /
45Change “Subtraction” to “Addition”If “Carry” = 1
ignore it, and the result is positive(in Binary)
If “Carry” = 0then the resultis negative(in 2’s Comp.)
0 1 0 1
+ 1 1 1 1
(5)10 – (1)10
(+5)10 + (-1)10
1 0 1 0 0
0 1 0 1
+ 1 0 1 0
(5)10 – (6)10
(+5)10 + (-6)10
0 1 1 1 1
+ 4 − 1
Binary Numbers and Binary Coding
Chapter 1 41
Flexibility of representation Within constraints below, can assign any binary
combination (called a code word) to any data as long as data is uniquely encoded.
Information Types Numeric
Must represent range of data needed Very desirable to represent data such that simple,
straightforward computation for common arithmetic operations permitted
Tight relation to binary numbers Non-numeric
Greater flexibility since arithmetic operations not applied.
Not tied to binary numbers
Non-numeric Binary Codes
Chapter 1 42
Given n binary digits (called bits), a binary code is a mapping from a set of represented elements to a subset of the 2n binary numbers.
Example: Abinary codefor the sevencolors of therainbow
Code 100 is not used
Binary Number 000001010011101110111
ColorRedOrangeYellowGreenBlueIndigoViolet
Number of Elements Represented
Chapter 1 43
Given n digits in radix r, there are rn distinct elements that can be represented.
But, you can represent m elements, m < rn
Examples: You can represent 4 elements in radix r = 2 with
n = 2 digits: (00, 01, 10, 11). You can represent 4 elements in radix r = 2 with
n = 4 digits: (0001, 0010, 0100, 1000). This second code is called a "one hot" code.
DECIMAL CODES - Binary Codes for Decimal Digits
Chapter 1 44
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 elements from the 16 binary numbers of 4 bits. A few are useful:
Binary Coded Decimal (BCD)
Chapter 1 45
The BCD code is the 8,4,2,1 code.
8, 4, 2, and 1 are weights
BCD is a weighted code
This code is the simplest, most intuitive binary code for decimal digits and uses the same powers of 2 as a binary number, but only encodes the first ten values from 0 to 9.
Example: 1001 (9) = 1000 (8) + 0001 (1)
How many “invalid” code words are there?
What are the “invalid” code words?
Excess 3 Code and 8, 4, –2, –1 Code
Chapter 1 46
What interesting property is common to these two codes?
Decimal Excess 3 8, 4, –2, –1
0 0011 0000
1 0100 0111
2 0101 0110
3 0110 0101
4 0111 0100
5 1000 1011
6 1001 1010
7 1010 1001
8 1011 1000
9 1100 1111
Warning: Conversion or Coding?
Chapter 1 47
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 iscoding)
ALPHANUMERIC CODES - ASCII Character Codes
Chapter 1 48
American Standard Code for Information Interchange
This code is a popular code used to represent information sent as character-based data. It uses 7-bits to represent:
94 Graphic printing characters. 34 Non-printing characters
Some non-printing characters are used for text format (e.g. BS = Backspace, CR = carriage return)
Other non-printing characters are used for record marking and flow control (e.g. STX and ETX start and end text areas).
ASCII Table
49
ASCII Properties
Chapter 1 50
ASCII has some interesting properties: Digits 0 to 9 span Hexadecimal values 3016 to 3916.
Upper case A-Z span 4116 to 5A16. Lower case a-z span 6116 to 7A16 .
• Lower to upper case translation (and vice versa) occurs byflipping bit 6.
Delete (DEL) is all bits set, a carryover from when punched paper tape was used to store messages. Punching all holes in a row erased a mistake!
PARITY BIT Error-Detection Codes
Chapter 1 51
A simple form of redundancy is parity, an extra bit appended onto the code word to make the number of 1’s odd or even. Parity can detect all single-bit errors and some multiple-bit errors.
A code word has even parity if the number of 1’s in the code word is even.
A code word has odd parity if the number of 1’s in the code word is odd.
Error Detecting Codes52 / 45
ParityOne bit added to a group of bits to make the total number of ‘1’s (including the parity bit) even or odd
Even
Odd
Good for checking single-bit errors
1 0 1 1 1 1 0 0 0 0 0 10
0 0 1 1 1 1 0 0 0 0 0 11
4-bit Example 7-bit Example
Gray Code
One bit changes fromone code to the nextcode
Different than Binary
Binary0000000100100011010001010110011110001001101010111100110111101111
53 / 45
Decimal
Gray
00 000001 000102 001103 001004 011005 011106 010107 010008 110009 110110 111111 111012 101013 101114 100115 1000