0% found this document useful (0 votes)
7 views36 pages

T1 Logic Design and Numbers

The document introduces digital design, emphasizing its importance in various fields such as computer, electrical, and software engineering. It explains the differences between analog and digital signals, focusing on binary digital signals and the process of digitization. Additionally, it covers number representation in binary and hexadecimal systems, including conversion methods and examples.

Uploaded by

liuyiduo0617
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views36 pages

T1 Logic Design and Numbers

The document introduces digital design, emphasizing its importance in various fields such as computer, electrical, and software engineering. It explains the differences between analog and digital signals, focusing on binary digital signals and the process of digitization. Additionally, it covers number representation in binary and hexadecimal systems, including conversion methods and examples.

Uploaded by

liuyiduo0617
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Topic 1

Introduction to Digital Design

1
Why Study Digital Design?
• Many elements of our lives are or are to
become digital
– Computer, AI, IoT, camera, cell phone, TV,
car...

• Solid understanding of this subject


benefits engineers
– For computer engineer – fundamental
– For electrical engineer – often necessary
– For software engineer – to be confident
and insightful when being aware of
hardware issues

2
“Digital” vs. “Analog”
• Analog signal • Digital signal
– Infinite possible values – Finite possible values
• Ex: voltage on a wire • Ex: button pressed on a
created by microphone keypad
Sound waves
move the
membrane, 1 2 3 4

2
which moves digital
the magnet,
signal
microphone
analog
which creates
signal
current in the nearby wire
Possible values: Possible values:
4

value
1.00, 1.01, 2.0000009, 3
0, 1, 2, 3, or 4.
value

That’s it.
... infinite possibilities 2
1
0
time
time
3
Digital Signals with Only Two Values: Binary
• Binary digital signal -- only two possible
values

value
– Typically represented as 0 and 1, respectively
– Everything is represented as combinations of 1
0
0’s and 1’s, e.g. 1011, 11010 time
• Called binary value or binary number
• Each binary digit is a bit
– We’ll only consider binary digital signals
• Although there are other types of digital signals
– Binary digital signal is popular because
• Transistors, the basic digital electric
component, operate at two voltages: low (e.g.
0V or -5V) and high (e.g. 3.3V or 5V)
• Storing/transmitting one of two values is easier
than three or more
4
From Analog to Digital (A2D) – Digitization
• Analog signal (e.g., audio)

Volts
may lose quality 3 distortion 3
– Voltage levels not 2 2
saved/copied/transmitted 1 original signal 1 received signal
perfectly 0
0
– Hard to recover time time
• Digitized version: Hard to fix, higher? lower?
01 10 11 10 11
– “Sample” voltage at
particular rate A2D distortion

Volts
– Easy to distinguish 0s
from 1s, thus easy to digitized signal 1
1
recover
0 0
– Increase sample rate to
improve quality time time
Can fix -- easily distinguish 0s
Example:
01 10 11 10 11 and 1s, restore
if only 4 sampled values
let binary representation be: D2A
Volts

3
0 V: “00”
2
1 V: “01”
2 V: “10” 1
0 time 5
3 V: “11”
From Analog to Digital – Digitization

Volts

Volts
3 3
2 2
1 original signal 1 recovered signal
Restore 0
0
time
01 10 11 10 11 01 10 11 10 11
(5 values)

6
Resolution

What happened?

(source: cntv.cn)

(source: wikipedia.org)

7
From Analog to Digital – Digitization

Volts

Volts
3 3
2 2
1 original signal 1 recovered signal
Restore 0
0
time
01 10 11 10 11 01 10 11 10 11
(5 values)
Volts

3
2 Restore
1 original signal
0
time

(20 values) Better recovered analog signal


Higher resolution (sample rate) More bits to represent more values 8
Typical Digital System
analog
phenomena

sensors and
other inputs
electric digital
signal data
Analog to digital
converter A2D
digital
data

Digital System

digital digital
data data
Digital to analog D2A
converter
electric
signal
actuators and
other outputs
9
How to Represent Numbers with Bits?
• Number systems: decimal, binary, octal, hexadecimal, …
– Base ten (decimal)

5 2 3
4 3 2 1 0
10 10 10 10 10

– Base two (binary)


1 0 1
4 3 2 1 0
2 2 2 2 2

• Each position of a number is associated with a weight


quantity
10
Binary System
• The Binary System is a base 2 (modulo 2) number system:
– 2 digits: 0 or 1
• Counting beyond 1 requires additional place
• In a binary number, each position has a decimal weight in
power of 2, 10011.01

1 0 0 1 1 . 0 1 0
×16 ×8 ×4 ×2 ×1 ½ ¼
weight (24) (23) (22) (21) (20) (2-1) (2-2)
position 4 3 2 1 0 -1 -2

11
Find Equivalent Decimal for Binary Numbers
• Example: Convert binary number 10011.012 to decimal

Number: 1 0 0 1 1 . 0 1 6
Position: 4 3 2 1 0 -1 -2
Weight: 24 23 22 21 20 2-1 2-2

1×24 + 0×23 + 0×22 + 1×21 + 1×20 + 0×2-1 + 1×2-2


= 16 + 0 + 0 +2 + 1 +0 + 1/4
Class Derivation
= 19.2510 = 10011.012

12
Encode Decimal as Binary Numbers:
Subtraction Method (Easy for Humans)

• Subtraction method Remaining quantity: 12


– To make the job easier (especially
for big numbers), we can just 32 16 8 4 2 1
subtract a selected binary weight 1 32 is
from the (remaining) quantity 32 16 8 4 2 1
too much

• Then, we have a new remaining


0 1 16 is
quantity, and we start again (from
the present binary position)
Class
32 16 8 4 2 1
too much
a

• Stop when remaining quantity is 0 0 Derivation


0 1 12 – 8 = 4
32 16 8 4 2 1

0 0 1 1 4-4=0
32 16 8 4 2 1 DONE

0 0 1 1 0 0 answer
32 16 8 4 2 1
13
Encode Decimal in Binary Numbers:
Division Method (Good for Computers)
• Example: Convert decimal number 37 to binary
– Repeated-division-by-base (here, base 2)
remainder
2 37 1 Least Significant Bit
2 18 0 (rightmost)
2 9 1
2 4 0
2 2 0
2 Class DerivationMost Significant Bit
1 1
0
(leftmost)

(37)10 = (100101)2

14
Encode Fractional Decimal in Binary
• Example: Convert fractional part 0.71510 to binary
– Repeated-multiplication-by-base (here, base 2)

Most Significant Bit


0.715  2 = 1 .430 1 (leftmost)
0.430  2 = 0 .860 0
0.860  2 = 1 .720 1
0.720  2 = 1 .440 1
0.440  2 = 0 .880 0 Least Significant Bit
(rightmost)

(0.715)10  (0.10110……)2

15
Encode Numbers with Bits
• More numbers need more bits to represent
– 3710 = 1001012 (6 bits)
– 13710 = 100010012 (8 bits)
– 1030710 = 101000010000112 (14 bits)

• N bits can represent 2N non-negative integers


– 0, 1, 2, …, 2N-1
– Negative numbers will be discussed later

16
Encode Decimal Numbers by Binary Bits
Binary Decimal
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
…… 1 0 0 0 8
1 0 0 1 9
1 0 1 0 10
1 0 1 1 11
1 1 0 0 12
1 1 0 1 13
1 1 1 0 14
1 1 1 1 15
16
……
…… 17
Hexadecimal System
• The Hexadecimal system is a base 16 (modulo 16)
number system:
– 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F
• Letters A ~ F represent decimal 10 through decimal 15
• Each position has a decimal weight in power of 16, e.g.
E3A
E 3 A 6
×256 ×16 ×1
weight (162) (161) (160)
(E3A)16 = E×256 + 3×16 + A×1 = 3584 + 48 + 10 = 3642
Class Derivation

18
Encode Decimal to Hexadecimal
• Example: Convert decimal number 58 to hexadecimal
– Repeated-division-by-base (here, base 16)

16 58 10 (A) Least Significant Digit


16 3 3
0 Class Derivation
Most Significant Digit

(58)10 = (3A)16

19
Summary
Binary Decimal Hexaecimal
0 0 0 0 0 0
0 0 0 1 1 1
0 0 1 0 2 2
0 0 1 1 3 3
0 1 0 0 4 4
0 1 0 1 5 5
0 1 1 0 6 6
0 1 1 1 7 7
1 0 0 0 8 8
1 0 0 1 9 9
1 0 1 0 10 A
1 0 1 1 11 b
1 1 0 0 12 C
1 1 0 1 13 d
1 1 1 0 14 E
1 1 1 1 15 F
20
Convert Binary to Hexadecimal
• Look for groups of 4 bits starting from the LSB
• Example: Convert 11 1011 0101.11 to hexadecimal:
11 1011 0101.11 = (0011 1011 0101.1100)2

3 b 5 c
Binary Decimal Hexaecimal
0 0 0 0 0 0
(11 1011 0101.11)2 = (3b5.c)16
Class Derivation 0
0
0
0 0
0 1
0 1
1
0
1
1
2
3
1
2
3
0 1 0 0 4 4
0 1 0 1 5 5
0 1 1 0 6 6
0 1 1 1 7 7
1 0 0 0 8 8
1 0 0 1 9 9
1 0 1 0 10 A
1 0 1 1 11 b
1 1 0 0 12 C
1 1 0 1 13 d
1 1 1 0 14 E21
1 1 1 1 15 F
Convert Hexadecimal to Binary
• Each digit is converted to 4 bits in binary
• Arrange the groups of 4 bits in the same order
• Example: convert (3F7)16 to binary:
(3 F 7)16 Binary Decimal Hexaecimal
0 0 0 0 0 0
0 0 0 1 1 1
0 0 1 0 2 2
0 0 1 1 3 3
( 0011 1111 0111 )2 0 1 0 0 4 4

Class Derivation
0 1 0 1 5 5
0 1 1 0 6 6
0 1 1 1 7 7
• Drop the initial 0’s to simplify 1 0 0 0 8 8
1 0 0 1 9 9
(3F7)16 = (11 1111 0111)2 1
1
0
0
1
1
0
1
10
11
A
b
1 1 0 0 12 C
1 1 0 1 13 d
1 1 1 0 14 E
1 1 1 1 15 F

22
Octal System
• The Octal number system is a base 8 (modulo 8) number
system:
– 8 digits: 0 1 2 3 4 5 6 7
• Each position has a decimal weight in power of 8
• Each octal digital corresponds to a 3-bit binary number
(3 1 7)8

( 011 001 111 )2

23
Convert Base-M System to Base-N System
• Decimal can always be used as the intermediate number
system
• Generally, the rule “divide/multiply by the base of
destination system” applies to all the number system
conversions
– Example, to convert a Hex number to base-3 number, just divide
the Hex number by 3

24
Binary and Hexadecimal Addition

• Binary Addition • Hexadecimal Addition


11110111 carry 111 carry
10110101 8F5A
+ 11010011 + 11BC
------------------------- ----------------------
110001000
Class Sum A116 Sum
Class
Derivation Derivation

25
How to Represent Text with Bits?
• A popular code: ASCII Symbol Encoding Symbol Encoding

(American Standard Code R


S
1010010
1010011
r
s
1110010
1110011
for Information Interchange) T 1010100 t 1110100
L 1001100 l 1101100
– 7- (or 8-) bit encoding of each N 1001110 n 1101110
letter, number, or symbol E 1000101 e 1100101
0 0110000 9 0111001
. 0101110 ! 0100001
<tab> 0001001 <space> 0100000

• Unicode: Increasingly Question:


popular 16-bit encoding What does this ASCII bit sequence represent?
– Encodes characters from 1010010 1000101 1010011 1010100
various world languages

REST

26
ASCII Coding Chart

27
How to Represent Signed Numbers with Bits?
• Cannot use minus sign, binary systems work with only two
values: 0 and 1
• The left-most bit of a binary number represents the sign of
a number – sign bit
– Sign bit 0 indicates positive numbers
– Sign bit 1 indicates negative number

28
Representation of Negative Numbers
• Negative numbers are represented by
– Sign and magnitude
– 1’s complement code
– 2’s complement code
• Sign and magnitude
– MSB is the sign bit: 0  positive, 1  negative
• 1’s complement representation of –N
– Negation of every bit of N
– Example, 1’s complement representation of -3
• N = 3 = 0011
Class Derivation
• -N = -3 = 1100
• 2’s complement representation of –N is
– Negation of every bit of N, then plus 1
– Example, 2’s complement representation of -3
• N = 3 = 0011
Class Derivation
• -N = -3 = 1100 + 1 = 1101

29
Signed 2’s Complement Number
• Signed numbers are represented as 2’s complement
numbers in computers
• Recognize a signed 2’s complement number
– Sign bit = 0, positive number, recognize as a regular binary number
• 0101 = +5;
– Sign bit = 1, negative number, the magnitude of the number is
obtained by 2’s complement operation
• 1011
– Sign: negative number
– Magnitude: 2’s complete operation of (1011) = 0100+1 = 0101 = 5
– So 1011 = 5

• Sign Extension (repeat sign bit w/o changing the value)


– 1011 = 11111011
– 0101 = 00000101
30
Binary Addition (revisit)
• Example:

Carry bits: 11110111 What are the signs and


10110101 = -7510 values of the numbers?
+ 11010011 = -4510
-------------------------
110001000 = -12010 for 10001000
Should the Carry be brought here?

No. This is a 8 bit system. Otherwise, it will


be 39210 in unsigned binary.
31
Binary Subtraction
• Using two’s complement representation
A – B = A + (-B)
= A + (two’s complement of B)
= A + invert_bits of B + 1
What are the signs and
values of the numbers?
• Example:
00111101
10110101 (A) 10110101 (A)
- 11010011 (B) + 00101100 (Inversion of B)
------------------------- + 1
-------------------
011100010
Should the Carry be brought here?
32
No, this is a 8 bit system.
Binary Arithmetic
• Example:

10010111 What are the signs and


10010101 = -10710values of the numbers?
+ 11010011 = -4510
-------------------------
101101000 = -15210 while 01101000 =
10410
Should the Carry be brought
here?
In this case, we need 9 bits to get
the correct answer.
33
Ranges of Signed 2’s Complement Number

In general the 2’s complement values range from 2n-1 to 2n-1-1


• For n = 4, the 2’s complement values range from 8 to 7
• For n = 8, the 2’s complement values range from 128 to 127
• For n = 16, the 2’s complement values range from 215 to 215-1

• Overflow
– If an n-bit 2’s complement number is greater than 2n-1-1 or less than 2n-1,
we say there is an overflow

34
Detecting Overflow: Method 1
• Overflow detection logic
– Two numbers’ sign bits are the same but are different from the result’s sign
bit
– If the two numbers’ sign bits are different, overflow is impossible
• Adding a positive and negative can’t exceed largest magnitude positive or
negative
• 4-bit examples

sign bits
0 1 1 1 1 1 1 1 1 0 0 0
+0 0 0 1 +1 0 0 0 +0 1 1 1

1 0 0 0 0 1 1 1 1 1 1 1
overflow overflow no overflow
(a) (b) (c)

35
Detecting Overflow - Method 2
• Simpler method: Detect difference between carry-in to sign bit and
carry-out from sign bit
c4 ≠ c3

0 1 1 1 1 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 0 0 0
+0 0 0 1 +1 0 0 0 +0 1 1 1

1 0 0 0 0 1 1 1 1 1 1 1
overflow overflow no overflow
(a) (b) (c)

• If the carry into the sign bit column differs from the
carry out of that column, overflow has occurred.
• When overflow occurs, one more bit (carry out) is needed.
36

You might also like