Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 66

CPEG 210

Digital Logic Design

Dr. Jibran K. Yousafzai


Office – A209, Ext. – 3719
E-mail – jyousafzai@auk.edu.kw

Chapter 1
Digital Systems & Binary Numbers
Goals

• The purpose of this course is that you:


–Learn what’s under the hood of digital
systems
–Learn the principles of digital design
–Gain an understanding of combinational and
sequential circuits
–Understand basic memory organization and
programmable logic
Chapter 1 :: Topics
• Background
• Digital vs. Analog
• Logic levels
• Number systems and conversions
• Conversions involving fractions
• Operations
• Coding

Background
• Digital systems have revolutionized our world
– Cell phones, Internet, rapid advances in medicine, etc.
• The semiconductor industry grew from $21 billion in 1985 to $213 billion
in 2004 and is expected to reach over $300 billion by 2013

• It enables the generation of some


$1,200 billion in electronic systems
business and $5,000
billion in services, representing close
to 10% of world GDP

The Digital
Abstraction
• Most physical variables
are continuous, for
example
– Voltage on a wire
– Frequency of an oscillation
– Position of a mass
• Instead of considering all values, the digital
abstraction considers only a discrete subset of values
– Considering discrete voltages instead of continuous voltages
used by analog circuits
– Digital circuits are simpler to design than analog circuits –
can build more sophisticated systems
– Digital systems replacing analog predecessors such as digital
cameras, digital television, cell phones, CDs etc.

Digital Systems
• Digital Computers are heavily employed in design
manufacturing, distribution and sales.
• General-purpose digital computing systems follow a
sequence of instructions, called an algorithm, and
implemented as a computer program that operates on
a given data.

• In digital computers, information are represented by


physical quantities called signals.

Signal
• An information variable represented by physical quantity.
• For digital systems, the variable takes on discrete values.
• Two level binary values are the most prevalent in digital systems.
• Binary values are represented abstractly by: – digits 0 and 1 (Bits)
– 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
• 1 and 0 can be represented by specific voltage levels, rotating gears, fluid
levels, etc.
• Digital circuits usually depend on specific voltage levels to represent 1
and 0
• Bit: Binary digit
Graph of an analog quantity

The Discretization Process - Sampling


Analog to Digital Conversion

Analog quantities have Digital quantities have


continuous values discrete sets of values
Digital to Analog Conversion

Logic Levels

• Define discrete voltages to represent 1 and 0


• For example, we could define:
– 0 to be ground or 0 volts
– 1 to be VDD or 5 volts
• What about 4.99 volts? Is that a 0 or a 1?
• What about 3.2 volts?
Logic Levels
• Define a range of voltages to represent 1
and 0
• Define different ranges for outputs and
inputs to allow for noise in the system
What is Noise?
• Anything that degrades the signal
– E.g., resistance, power supply noise, coupling to neighboring
wires, etc.

• Example: a gate (driver) could output a 5 volt signal


but, because of resistance in a long wire, the signal
could arrive at the receiver with a degraded value, for
example, 4.5 volts
• Given logically valid inputs, every circuit element must
produce logically valid outputs
Noise
Driver Receiver

5V 4 .5 V
Logic Levels
Driver Receiver

Output Characteristics Input Characteristics


VDD
Logic High
Output Range Logic High
VOH Input Range
NMH
Forbidden VIH
Zone VIL
VO L NML Logic Low
Logic Low Input Range
Output Range
GND

The HIGH range typically corresponds to binary 1 and LOW range to binary 0.
The forbidden zone (or the threshold region) is a range of voltages for which
the input voltage value cannot be interpreted reliably as either a zero (0) or a
one (1).
Noise Margins
Driver Receiver

Output Characteristics Input Characteristics


VDD
Logic High
Output Range Logic High
VOH Input Range
NMH
Forbidden VIH
Zone VIL
VO L NML Logic Low
Logic Low Input Range
Output Range
GND

NMH = VOH – VIH


NML = VIL – VOL
Other physical quantities
What are other physical quantities that represent 0s and
1s?

– CPU: Voltage
– Disk: Magnetic Field Direction
– CD: Surface Pits/Light
– Dynamic RAM: Electrical Charge
NUMBER SYSTEMS
Commonly occurring bases

Name Radix Digits


Binary 2 0,1
Octal 8 0,1,2,3,4,5,6,7
Decimal 10 0,1,2,3,4,5,6,7,8, 9

Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Numbers in different bases
Decimal Binary Octal Hexadecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 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
16 10000 20 10
Binary-Decimal Conversions
• To convert from binary to decimal, use
decimal arithmetic to form S (digit ×
respective power of 2).
• Example: Convert 110102 to N10:
– (11010)2 = 0 x 20 + 1 x 21 + 0 x 22 + 1 x 23 + 1 x 24 = (26)10

Binary-Decimal Conversions
• To convert from decimal to binary
– Subtract the largest power of 2 that gives a positive
remainder and record the power.
– Repeat, subtracting from the prior remainder and
recording the power, until the remainder is zero.
– Place 1’s in the positions in the binary result
corresponding to the powers recorded; in all other
positions place 0’s.
• Example: Convert 62510 to N2

Binary-Decimal Conversions
• Decimal numbers

537410 =
• Binary numbers

11012 =

Binary-Decimal Conversions
• Decimal numbers

537410 = 5 × five103 + 3 three× 102 + 7seven × 101 + 4 four× 100


thousands hundreds tens ones

• Binary numbers
11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 1310
one one no one eight four two one

Powers of Two
• 20 = • 28 =
• 21 = • 2 9 = • 22 = • 210 =
• 23 = • 211 =
• 24 = • 212 =
• 25 = • 213 =
• 26 = • 214 =
• 27 = • 215 =
Powers of Two
• 20 = 1 • 29 = 512
• 21 = 2 • 210 = 1024
• 22 = 4 • 211 = 2048
• 23 = 8 • 212 = 4096
• 24 = 16 • 213 = 8192
• 2 = 32
5 • 214 =
• 26 = 64 16384
• 2 = 128
7 • 215 =
• 28 = 32768
256
• Handy to memorize up to 29
Binary-Decimal Conversions

Decimal to binary conversion:

Convert 100112 to decimal


Decimal to binary conversion:

Convert 4710 to binary
Binary-Decimal Conversions

Decimal to binary conversion:

Convert 100112 to decimal

16×1 + 8×0 + 4×0 + 2×1 + 1×1 = 1910


Decimal to binary conversion:

Convert 4710 to binary

32×1 + 16×0 + 8×1 + 4×1 + 2×1 + 1×1 = 1011112
Binary Values and Range
• N - digit decimal number
– How many values? 10N
– Range? [0, 10N - 1]
– Example: 3-digit decimal number:
• 103 = 1000 possible values
• Range: [0, 999]

• N - bit binary number


– How many values? 2N
– Range: [0, 2N - 1]
– Example: 3-digit binary number:
• 23 = 8 possible values
• Range: [0, 7] = [0002 to 1112]
Hexadecimal Numbers
• Base 16
• Shorthand to write long binary numbers
• Make groups of 4 binary numbers to form
hexadecimal numbers
Octal Numbers
• Base 8
• Shorthand to write long binary numbers
• Make groups of 3 binary numbers to form
hexadecimal numbers

Some more conversions



Convert 14510 to binary, hexadecimal and octal

Convert 4AF16 (also written 0x4AF) to decimal,
binary and octal

Convert 1001010112 to decimal, hexadecimal and
octal

Convert 1458 to decimal, binary and hexadecimal
Some more conversions

Hexadecimal to binary conversion:

Convert 4AF16 (also written 0x4AF) to binary
– 0100 1010 11112


Hexadecimal to decimal conversion:

Convert 4AF16 to decimal

162×4 + 161×10 + 160×15 = 119910

Bits, Bytes, Nibbles…


• Bits 10010110
most least significant significant

bit bit

• Bytes & Nibbles byte

10010110
nibble

• Bytes
CEBF9AD7
most least
significant significant byte
byte

Powers of Two
• 2 10 = 1 kilo ≈ 1000 (1024)
• 2 20 = 1 mega ≈ 1 million (1,048,576)
• 2 30 = 1 giga ≈ 1 billion (1,073,741,824)
Estimating Powers of Two
• What is the value of 224?

• How many values can a 32-bit variable


represent?

Estimating Powers of Two


• What is the value of 224?
- 24 × 220 ≈ 16 million
• How many values can a 32-bit variable
represent?
- 22 × 230 ≈ 4 billion

CONVERSIONS
INVOLVING FRACTIONS
Conversions involving fractions
• To convert a number with a fractional part
from one base to another:
– Convert the integer part
– Convert the fraction part
– Join the two results with a radix point
Conversions involving fractions
• To convert the integer 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. If the new radix is > 10, then convert
all remainders > 10 to digits A, B, …

• 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, …

Example: Convert 46.687510 to binary


• Convert 46 to binary
– 1011102

• Convert 0.6875 to binary


– 0.10112

• Join the results together with the radix point:


– 101110.10112

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.

Check your answer


• To convert back, sum the digits times their respective powers
of the base.

• From the prior conversion of 46.687510

1011102 = 1·32 + 0·16 +1·8 +1·4 + 1·2 +0·1


= 32 + 8 + 4 + 2
= 46
0.10112 = 1/2 + 1/8 + 1/16
= 0.5000 + 0.1250 + 0.0625
= 0.6875

Octal (Hexadecimal) to Binary and Back


• Octal (Hexadecimal) to Binary:
– Restate the octal (hexadecimal) as three (four) binary digits starting
at the radix point and going both ways.

• Binary to Octal (Hexadecimal):


– Group the binary digits into three (four) bit groups starting at the
radix point and going both ways, padding with zeros as needed in
the fractional part.

– Convert each group of three bits to an octal (hexadecimal) digit.


Example
• Binary to Octal (Hexadecimal):
– (010 110 001 101 011 111 100 000 110)2 =
( 2 6 1 5 3 7 4 0 6)8
• Hexadecimal (Octal) to Binary:
–( 2 c 6 b f 0 6)16 =
(0010 1100 0110 1011 1111 0000 0110)2

Octal to Hexadecimal via Binary


• Convert octal to binary.
• Use groups of four bits and convert as above to
hexadecimal digits.
• Example: Octal to Binary to Hexadecimal
(6 3 5 . 1 7 7)8
Octal (Hexadecimal) to Decimal and Back

• Octal (Hexadecimal) to Decimal:


– (127.4)8 = 1 x 82 + 2 x 81 + 7 x 80 + 4 x 8-1 =
(87.5)10
– Similarly for Hexadecimal

• What about backwards?


Addition
carries
11
• Decimal 3734

• Binary
11
1011 carries
OPERATIONS
Single Bit Binary Addition with Carry
Given two binary digits (X,Y), a carry in (Z) we get the
following sum (S) and carry (C):
Z 0 0 0 0
Carry in (Z) of 0: X 0 0 1 1
+Y

Carry in (Z) of 1:
Z 1 1 1 1
X 0 0 1 1
CS 00
+Y
CS 01

Binary Addition Examples


• Add the following 4-bit 1001 binary numbers
+ 0101

• Add the following 4-bit 1011 binary numbers


+ 0110

Binary Addition Examples


1
• Add the following 4-bit 1001 binary numbers

111
• Add the following 4-bit 1011
binary numbers

Overflow!
Overflow

Digital systems operate on a fixed number
of bits

Addition overflows when the result is too
big to fit in the available number of bits

See previous example of 11 + 6
Subtraction: Signed Binary Numbers
• Sign/Magnitude Numbers
• Two’s Complement Numbers
Sign/Magnitude Numbers

1 sign bit, N-1 magnitude bits

Sign bit is the most significant (left-most) bit
– Positive number: sign bit = 0
– Negative number: sign bit = 1


Example, 4-bit sign/mag representations of ± 6:
+6 = 0110
- 6 = 1110

Range of an N-bit sign/magnitude number:
[-(2N-1-1), 2N-1-1]
Sign/Magnitude Numbers
• Problems:

Addition doesn’t work, for example -6 + 6:
1110
+ 0110

10100 (wrong!)

Two representations of 0 (± 0):
1000
0000
Two’s Complement Numbers
• Don’t have same problems as
sign/magnitude numbers:
– Addition works
– Single representation for 0
Two’s Complement Numbers
• Same as unsigned binary, but the most significant bit
(msb) has value of -2N-1
• Most positive 4-bit number: 0111
• Most negative 4-bit number: 1000
• The most significant bit still indicates the sign
(1 = negative, 0 = positive)
• Range of an N-bit two’s comp number: [-(2N-1), 2N-1-1]
“Taking the Two’s Complement”

Flip the sign of a two’s complement
number

Method:
1. Invert the bits
2. Add 1


Example: Flip the sign of 310 = 00112
“Taking the Two’s Complement”

Flip the sign of a two’s complement
number

Method:
1. Invert the bits
2. Add 1


Example: Flip the sign of 310 = 00112
1. 1100
2. + 1
1101 = -310

Two’s Complement Examples



Take the two’s complement of 610 =
01102

What is the decimal value of 10012?

Two’s Complement Examples



Take the two’s complement of 610 =
01102
1. 1001
2. + 1
10102 = -610


What is the decimal value of the two’s
complement number 10012?
1. 0110
2. + 1

01112 = 710, so 10012 = -710

Two’s Complement Addition


• Add 6 + (-6) using two’s complement
numbers 111
0110

• Add -2 + 3 using two’s complement


numbers 111
1110

Increasing Bit Width


• A value can be extended from N bits to M bits
(where M > N) by using:
– Sign-extension
– Zero-extension

Sign-Extension

Sign bit is copied into most significant bits.

Number value remains the same.


Example 1:
– 4-bit representation of 3 = 0011 –
8-bit sign-extended value:
00000011

Example 2:
– 4-bit representation of -5 = 1011
– 8-bit sign-extended value: 11111011

Zero-Extension

Zeros are copied into most significant bits.

Value will change for negative numbers.


Example 1:
– 4-bit value = 00112 = 310
– 8-bit zero-extended value: 00000011 = 310


Example 2:
– 4-bit value = 1011 = -510
– 8-bit zero-extended value: 00001011 = 1110

Number System Comparison


Number System Range
Unsigned [0, 2N-1]
Sign/Magnitude [-(2N-1-1), 2N-1-1]
Two’s Complement [-2N-1, 2N-1-1]
For example, 4-bit representation:
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Unsigned 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Two's Complement

0000
1111 1110 1101 1100 1011 1010 1001 0001 0010 0011 0100 0101 0110 0111 Sign/Magnitude
1000

Binary multiplication
• The binary multiplication table is simple:
0 0=0 | 1 0=0 | 0 1=0 | 1 1=1
• Extending multiplication to multiple digits:
Multiplicand 1011
Multiplier x 101
Partial Products 1011
0000-
1011 --
Product 110111

Multiplication/Division by 2n
• Multiplication by 1002 B3 B2 B1 B0

– Shift left by 2 0
0
C

C5 C4 C3 C2 1 C0
0

C
B3 B2 B1 B0
• Division by 1002
– Shift right by 2 0

C3 2 C1 C0 C- 1 C- 2
(b)

CODING
ASCII Character Codes
• 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).
UNICODE
• UNICODE extends ASCII to 65,536 universal characters codes
– For encoding characters in world languages
– Available in many modern applications
– 2 byte (16-bit) code words
– See Reading Supplement – Unicode on the Companion
Website http://www.prenhall.com/mano

Binary Codes for Decimal Digits


Decimal 8, 4, 2, 1 Excess 3 8, 4, -2, -1 Gray
0 0000 0011 0000 0000
1 0001 0100 0111 0001 2 0010 0101
0110 0011
3 0011 0110 0101 0010
4 0100 0111 0100 0110 5 0101 1000 1011 0111
6 0110 1001 1010 0101
7 0111 1010 1001 0100
8 1000 1011 1000 1100
9 1001 1100 1111 1101

There are over 8,000 ways that you can chose 10 elements from the 16 binary
numbers of 4 bits.

Binary Coded Decimal (BCD)


• The BCD code is the 8,4,2,1 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?

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)

• Yellow 101 (This is coding)

• 13 0001|0011 (This is also coding)


BCD Arithmetic
Given a BCD code, we use binary arithmetic to add the digits:
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
Note that the result is MORE THAN 9, so must be represented by two
digits! To correct the digit, subtract 10 by adding 6 modulo 16.
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
+0110 so add 6
carry = 1 0011 leaving 3 + cy
0001 | 0011 Final answer ( two digits)

If the digit sum is > 9, add one to the next significant digit
BCD Addition Example
• Add 448BCD to 489BCD showing carries and digit
corrections.

1 1 0

0100 0100 1000


+ 0100 1000 1001
1001 1101 1 0001
+ 0110 + 0110

1001 1 0011 1 0111


9 3 7
Why add 6?
• Take the largest two BCD numbers and add
them:
–9+9+1=1 9

Carry In

• In binary:
– 1001 + 1001 + 1 = 1 0011 = 13 and not 19 –
The difference is 6!

End of chapter !

You might also like