You are on page 1of 43

EEE 21

Switching Theory and Digital


Logic Design
Lecture 1
Analog and Digital Systems
Number Systems

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

1/43

Analog vs. digital


l

Electronic signals may be


l

Continuous in amplitude and in time

Continuous in amplitude
and discrete in time

Discrete in amplitude and continuous


in time

Discrete in amplitude
and discrete in time
4 5 4 3 4 6 7 5 3 3 4 4 3

2/43

Analog vs. digital


Special case: system that only uses two voltages (HIGH and
LOW).
l
l

high voltage may be considered a logic 1


low voltage may be considered a logic 0
voltage
5V

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

0V
time
l

Other example: optical system (presence / absence of light)


EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

3/43

voltage

Analog signal

time

Analog to Digital Conversion



1. Sample the signal at a
sampling frequency fS
2. Quan=ze to specied levels

sample

voltage

Digital signal
quan1ze
time

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

time

4/43

Representing digital systems


Switches
l Boolean algebra / equations
l Truth tables
l Gates / circuits
l Block diagrams
l Waveforms / timing diagrams
l State diagrams
l Hardware description languages
l

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

5/43

Example - switches
l

Switches connect two points under the control


of a signal
l
l
l

true if the control condition or event occurs


false if the event does not occur
opens or closes based on the state of the signal

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

6/43

Example - switches
l

IF {car running
AND [car in driveway OR
(car in garage AND NOT garage door closed) ]
}
THEN car can back out

7/43
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

Two main classes


l

Combinational logic - the output at any given time is a


function solely of the combination of some or all of the inputs
at that given time

Inputs

xn-1
xn-2
x1
x0

Combinational
Logic

zm-1
zm-2
z1
z0

Outputs

The value of any output variable zk depends only on the


present values of the input variables xi
System is memoryless, i.e., outputs do not depend on any
history of the inputs or previous state of the system
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

8/43

Two main classes


l

Inputs

Sequential logic the output depends not only on the


current input, but also on the systems history.
l In response to a given sequence of inputs, the system
also goes through a predictable sequence of states
xn-1
x0

:
Combinational
Logic

Current
State

zm-1
z0 Outputs

Next
State

Memory
l

The current outputs as well as the next state of the


system, depend on the current inputs and current state9/43

Sequential systems
l

Synchronous sequential circuit a reference signal


called the clock causes the system to change state at a
specific instant in time

Asynchronous sequential circuit the change in state is


not dictated by a reference signal

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

10/43

NUMBER SYSTEM

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

11

Cardinality
l

Measure of the number of elements of a given set S


l Denoted by |S|

In number systems, we are interested in the set of symbols


D that represent the digits of that system
l Binary number system
|D| = 2 D = {0,1}
l Octal number system
|D| = 8 D = {0,1,2,3,4,5,6,7}
l Hexadecimal number system
|D| = 16 D = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

12/43

Number representation

To represent k discrete quantities in a number system that


uses a set of symbols D to represent digits, you would
need at least n digits to represent each quantity such that

|D|n-1 k |D|n

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

13/43

Number representation
l

Example: How many digits would you need to be able to


represent at least 5 quantities using the binary system?
D = {0,1}, therefore |D| = 2
2n-1 5 2n

Answer: n = 3, that is, you would need at least 3 bits


(binary digits)
With n = 2, you can only form the numbers 00, 01, 10 and 11
With n = 3, you can form the numbers
000, 001, 010, 011, 100, 101, 110 and 111
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

14/43

Number representation
l

Example: Let's say you can use colored dots from D =


{RED,GREEN,BLUE} to tag 5 different items. What is the
minimum number of dots that you need on each item to
uniquely identify each one, assuming each item has to be
tagged with the same number of dots?
3n-1 5 3n
Answer: n = 2
How many different items can you tag using this scheme?
Can tag a maximum of 9 items:
BB, BG, BR, GB, GG, GR, RB, RG, GG
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

15/43

Number representation
l

tuple - an ordered list of objects, each of a specified type

n-tuple - a group of n digits (or labels) used to represent


each number (or item)
l

An n-tuple that uses a set of symbols D can represent


up to |D|n items
l For numbers, a system that uses n digits and the set
D as digit symbols can represent up to |D|n quantities

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

16/43

Number representation
l

Example: How many values can you represent using


4-bit binary numbers?
Answer:

D = {0,1}, thus |D| = 2


The maximum number of values you can represent using
n = 4 bits (binary digits) is

|D|n = 24 = 16 values
These are 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111,
1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

17/43

Number representation
l

Easy way to remember this:


Given n digits in each number (or tuple) and k symbols
(k = |D|), the maximum number of unique quantities or
values that can be represented is given by
There are k possible symbols for each digit

A digit's
position
in the number

(k) (k) (k) (k)



There are n digit positions

Multiplying k with itself n times gives us kn


EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

18/43

Number representation
l

Example: How many values can you represent using 4-bit


binary numbers?

D = {0,1}, thus |D| = k = 2


The maximum number of values you can represent using
4 bits (binary digits) is
Choice of {0,1}
for each digit

(2) (2) (2) (2)

= 24

= 16 values


These are 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111,
1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

19/43

Positional number systems


l

each digit carries a weight associated with


its position relative to the radix point
1,234.56 (in decimal)
=

1 x 1000 = 1 x 103 = 1000


+ 2 x 100 = 2 x 102 = 200
+ 3 x 10 = 3 x 101 = 30
+ 4 x 1 = 4 x 100 = 4
+ 5 x 0.1 = 5 x 10-1 = 0.5
+ 6 x 0.01 = 6 x 10-2 = 0.06
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

20/43

Positional number systems


l

Example of a non-positional system


Roman numeral MCMLXVII = 1967

In contrast, the current decimal (base-10)


system is positional
103 102 101 100 10-1 10-2 10-3

1234.567
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

21/43

Positional number systems


l

In general, for a number with


l base or radix r,
l n digits in the integer part
l m digits in the fractional part
integer part

fractional part

n-1

an-1an-2...a1a0.a-1a-2...a-m = ai x ri
i = -m

radix point: separates


the integer from
fractional part
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

22/43

Base conversion
l

Example: What quantity (in base-10) is


represented by the binary number 101110.0112?
101110.0112
1 x 2-3 = 1 x 1/23 = 1 x 1/8 = 1 x 0.125 = 0.125
1 x 2-2 = 1 x 1/22 = 1 x 1/4 = 1 x 0.25 = 0.25
0 x 2-1 = 0 x 1/21 = 0 x 1/2 = 0 x 0.5 = 0
0 x 20 = 0 x 1 = 0
1 x 21 = 1 x 2 = 2
1 x 22 = 1 x 4 = 4
1 x 23 = 1 x 8 = 8
0 x 24 = 0 x 16 = 0
1 x 25 = 1 x 32 = 32

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

= 46.37510

23/43

Base conversion
l

Previous procedure essentially describes


how to convert number in base r to the
same number in base 10

How to convert a number in base 10 to its


base r representation?

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

24/43

Multiplication by the radix


l

Example: 1234.567810
l
l

1234.567810 x 1010 = 12345.67810


1234.567810 / 1010 = 123.4567810

In general
l
l

Multiplying a base-r number by r moves the


radix point to the right
Dividing a base-r number by r moves the radix
point to the left
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

25/43

Base conversion
l

Converting a base-10 fraction to base-r


unknown

F = (.a-1a-2...a-m)r
(F)(r) = (a-1 . a-2...a-m)r
(F)(r) = some integer + fraction F'
Therefore, (a-1)r = integer
Repeat using F' and (.a-2a-3...a-m)r.
Sometimes this process does not terminate...
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

26/43

Base conversion
l

Example: 0.710 = (?)2 up to 5 bits after the binary point


unknown

0.710 = (.a-1a-2a-3a-4a-5)2
(0.7)(2) = 1. 4 = (a-1. a-2a-3a-4a-5...)2
(0.4)(2) = 0.8 = (a-2.a-3a-4a-5...)2
(0.8)(2) = 1.6 = (a-3.a-4a-5...)2
(0.6)(2) = 1.2 = (a-4.a-5...)2
(0.2)(2) = 0.4 = (.a-5...)2
0.710 (0.10110)2

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

a-1 = 1
a-2 = 0
a-3 = 1
a-4 = 1
a-5 = 0

27/43

Base conversion
l

Converting an integer in base-10 to base-r


unknown

D = (an-1an-2...a1a0)r
D/r = (an-1an-2...a1. a0)r
D/r = some integer D' + (remainder)/r
Now (.a0)r = a0/r = remainder/r
Therefore a0= remainder
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

28/43

Base conversion
l

Repeat with the integer from previous step


D' = (an-1an-2...a1)r
D'/r = (an-1an-2...a2 . a1)r
D'/r = some integer D'' + (remainder)/r
Similarly, (.a1)r = a1/r = remainder/r
Therefore a1= remainder
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

29/43

Base conversion
l

Example: Convert 1234 to its hex equivalent


Recall 16 hex digit symbols
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
Helps to know how many digits in the answer...
l 2 hex digits? (16)(16) = 162 = 256 < 1234
l 3 hex digits? (16)(16)(16) = 163 = 4096 > 1234
so n = 3 digits in the answer
1234/16 = 77 remainder 2
77/16 = 4 remainder 13
4/16 = 0 remainder 4
So a2a1a0 = 4D216 = 0x4D2 = 4D2h
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

a0 = 2
a1 = D
a2 = 4
30/43

Base Conversion (Summary)


Conversion from Base r to Decimal

Multiply each digit by its weight relative to its position,


then add all the products
Ar4 + Br3 + Cr2 + Dr1 + Er0 . X r -1 + Yr -2 +

Conversion from Decimal to Base r

Integer part: Continuously DIVIDE by r and note the


remainder after each division
Fractional part: Continuously MULTIPLY by r and note
the integer portion after each multiplication
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

31/43

Examples
11011.012 = ( ? )10

11011.012 = 27.2510

12506 .178 = ( ? )10

12506 .178 = 5446.23410

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

32

Examples
56.710 = ( ? )2
0.710 = ( ? )2

5610 = ( ? )2
2 /56
2 /28
2 /14
2 /7
2 /3
2 /1
0

2 * .7 = 1.4
2 * .4 = 0.8
2 * .8 = 1.6
2 * .6 = 1.2
2 * .2 = 0.4

.
0
0
0
1
1
1

1
0
1
1
0

0.710 = 0.101102

5610 =1110002

56.710 = 111000.101102

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

33/43

Octal to/from binary


l

An octal digit (base 8) is ALWAYS equal to three (3)


binary digits,
Simply replace the octal digit with the corresponding
binary digits and vice-versa
Octal

Binary

000

001

010

011

100

101

110

111

Example:

12506178 = 001 010 101 000 110 001 111 2


From EEE 11

34

Hexadecimal to/from binary


l

A hexadecimal (base 16) digit is ALWAYS equal to


four (4) binary digits,
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

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

Example:

E25A61716 =
1110 0010 0101 1010 0110 0001 0111 2
From EEE 11

35

Hexadecimal to/from Octal


l

Expand first to binary then group by 4 or 3 depending on


the destination
e.g.
ABC16
= (?)8
= A
B
C
16
= 1010 1011 1100 2
regroup by 3's ...
= 101 010 111 100 2
= 5
2
7
48
= 5274 8
From EEE 11

36/43

Binary arithmetic
l

Addition
0+0=0
0+1=1
1+0=1
1 + 1 = 0 carry 1

111
1
(carry)
00011001
+ 00101101
01000110
EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

37/43

Binary arithmetic
l

Multiplication

Each bit in the multiplier (starting from the least significant bit
or LSB) is multiplied to each bit of the multiplicand in
much the same way that decimal numbers are multiplied.

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

38/43

Codes
Other ways of representing quantities or objects
l

Binary coded decimal: each decimal digit is


represented by a 4-bit code. The resulting
codeword cannot be manipulated in the same
manner as a binary number
4510 0100 0101

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

39/43

Codes
Other ways of representing quantities or objects
l

Reflected code: patented in 1947 by Bell Labs


researcher Frank Gray (thus also called Gray
code)
l For reflected binary Gray code, two successive
codewords differ in only one bit position
2-bit Gray code
00
01
11
10

Mirror images (reflection)

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

40/43

Codes
3-bit Gray code
Start with 2-bit Gray code
000
001
011
010
110 Reflect
111
101
100

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

41/43

Codes
Error-correcting and error-detecting codes
l

Parity check code

Even parity:

11010111

Odd parity:

01010111

sum of all bits (including the


parity bit) is even.
sum of all bits (including the
parity bit) is odd.

parity bit

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

42/43

Codes
Character codes: (Example) ASCII (American
Standard Code for Information Interchange)
l

Specifies correspondence between a set of bit patterns


and the glyphs (i.e. symbols) of a written language
Binary
100 0000
100 0001
100 0010
100 0011
100 0100
100 0101
100 0110
100 0111
100 1000

Oct
100
101
102
103
104
105
106
107
110

Dec
64
65
66
67
68
69
70
71
72

Hex
40
41
42
43
44
45
46
47
48

EEE 21. A. Ballesil, R. Ocampo, J. Pedrasa

Glyph
@
A
B
C
D
E
F
G
H
l

[Wikipedia] 43/43

You might also like