数字逻辑设计及应用
DESCRIPTION
Digital Logic Design and Application ( 数字逻辑设计及应用 ). 数字逻辑设计及应用. Chapter 2 Number Systems and codes ( 数系与编码 ) 介绍在数字逻辑体系中信号的 表达方式 、 类型 ,不同表达方式之间的 转换 , 运算 的规则等。. Digital Logic Design and Application ( 数字逻辑设计及应用 ). Review of Chapter 1 ( 第一章内容回顾 ). - PowerPoint PPT PresentationTRANSCRIPT
1
数字逻辑设计及应用Chapter 2 Number Systems and codes
(数系与编码 )
介绍在数字逻辑体系中信号的表达方式、类型,不同表达方式之间的转换,运算的规则等。
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2
Review of Chapter 1 (第一章内容回顾 )
Analog versus Digital (模拟与数字 )
Digital Devices (数字器件 ): Gates (门电路)、 Flip-flops(触发器)
Electronic and Software Aspects of
Digital Design
(数字设计的电子技术和软件技术 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
3
Review of Chapter 1 (第一章内容回顾 )
Integrated Circuit( IC,集成电路)Programmable Logic
Devices( PLA、 PLD、 CPLD、 FPGA, 可编程逻辑器件)
Application-Specific ICs( ASIC, 专用集成电路)
Printed-Circuit Boards (PCB, 印制电路板 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
4
Chapter 2 Number Systems and codes
(数系与编码 )
Two kinds of Information
(信息主要有两类 ):
Numeric Data (数值信息 )
Nonnumeric Data (非数值信息 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
— Number Systems and their Conversions
( 数制及其转换 )
-- Nonnumeric Data Representation – Codes ( 非数值信息的表征 -- 编码 )
5
Chapter 2 Number Systems and codes
(数系与编码 )
数字系统只处理数字信号 0 , 1;需要将任意信息用 ( 0 ,1 )表达;用( 0, 1 )表达数量: 数制 二进制用( 0, 1 )表达不同对象: 符号编码
Digital Logic Design and Application ( 数字逻辑设计及应用 )
66
How to Encode Text: ASCII, Unicode
ASCII: 7- (or 8-) bit encoding of each letter, number, or symbol
Sample ASCII encodingsSymbolEncoding
010 0000 <space>␠010 0001 !010 0010 "010 0011 #010 0100 $010 0101 %010 0110 &010 0111 '010 1000 (010 1001 )010 1010 *010 1011 +010 1100 ,010 1101 -010 1110 .010 1111 /
SymbolEncoding
100 1110 N100 1111 O101 0000 P101 0001 Q101 0010 R101 0011 S101 0100 T101 0101 U101 0110 V101 0111 W101 1000 X101 1001 Y101 1010 Z
100 0001 A100 0010 B100 0011 C100 0100 D100 0101 E100 0110 F100 0111 G100 1000 H100 1001 I100 1010 J100 1011 K100 1100 L100 1101 M
SymbolEncoding
SymbolEncoding
011 0000 0011 0001 1011 0010 2011 0011 3011 0100 4011 0101 5011 0110 6011 0111 7011 1000 8011 1001 9
110 0001 a110 0010 b ...111 1001 y111 1010 z
… …
77
How to Encode Text: ASCII, Unicode
Unicode: Increasingly popular 16-bit encodingEncodes characters from various world
languages
… …
88
How to Encode Numbers: Binary Numbers
Base ten (decimal) Ten symbols: 0, 1, 2, ..., 8,
and 9 More than 9 -- next
position
So each position power (幂) of 10
Nothing special about base 10 -- used because we have 10 fingers
104 103 102
5 2 3
101 100
• Each position represents a base quantity; symbol in position means how many of that quantity
99
How to Encode Numbers: Binary Numbers
Base two (binary)Two symbols: 0
and 1More than 1 -- next
positionSo each
position power (幂) of 2
2 4 2 3 2 2
1 0 1
2 1 2 0
Q: How much?
+
=
4
1 5
+
=
a
• Each position represents a base quantity; symbol in position means how many of that quantity
There are only 10 types of people in the world: those who understand binary, and those who don't.
1010
Useful to know powers of 2:
24 23 22 21 2029 28 27 26 25
16 8 4 2 1512256128 64 32
16 8 4 2 1512 256 12864 32
Practice counting up by powers of 2:
11
2.1 Positional Number System (按位计数制 )
Any Decimal Number D Can Be Represented as
the Following ( 任意十进制数 D 可表示如下 ):
D = dp-1 dp-2 ... d1 d0 . d-1 d-2 ... d-n
推广: D2 = ∑ d i × 2i
D16= ∑ d i × 16i
1p
ni
ii rd
Weight of i bit; Base or Radix of r Number System(第 i 位的权; r 计数制的基数 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
12
2.1 Positional Number System (按位计数制 )
按位计数制的特点 1) 采用基数(Base or Radix), R进制的基数是 R
2) 基数确定数符的个数 如十进制的数符为:
0、 1、 2、 3、 4、 5、 6、 7、 8、 9,个数为 10
二进制的数符为: 0、 1,个数为 2
3)逢基数进一
Digital Logic Design and Application ( 数字逻辑设计及应用 )
13
2.1 Positional Number System (按位计数制 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
Decimal and Binary
Decimal system: base is 10, the digit may be 0 to 9
101210 1011011001011.101
Binary system: base is 2, the digit may be 0 or 1
10122 212120211.101
bit: one digit in binary system;
1414
Using Digital Data in a Digital System
temperature sensor
0 0 1 10 0 0 0 "33"
A temperature sensor outputs temperature in binary
The system reads the temperature, outputs ASCII code:“F” for freezing (0-32)“B” for boiling (212 or more)“N” for normal
1515
Using Digital Data in a Digital System
temperature sensor
0 0 1 10 0 0 0 "33"
Digital System
display N
"N"1 0 00 1 1 1
if (input <= "00100000") // "32" output = "1000110" // "F"else if (input >= "11010100") // "212" output = "1000010" // "B"else output = "1001110" // "N"
A display converts its ASCII input to the corresponding letter
16
2.2 Octal and Hexadecimal Numbers
(八进制和十六进制 )
基数 数码 特性 Octal Number ( 八进制 ) 8 0~7 逢八进一 Binary Number ( 二进制 ) 2 0,1 逢二进一
Hexadecimal Number( 十六进制 )
16 0~9,A~F 逢十六进一
Digital Logic Design and Application ( 数字逻辑设计及应用 )
17
说 明Digital Logic Design and Application ( 数字逻辑设计及应用 )
选择什么数制来表示信息, 对数字系统的成本和性能影响很大, 在数字电路中多使用二进制 .
Most Significant Bit(MSB, 最高有效位)Least Significant Bit( LSB, 最低有效位)
1011100010112
MSB LSB
18
Digital Logic Design and Application ( 数字逻辑设计及应用 )
表 2.1 十进制、二进制、八进制与十六进制数
十进制 二进制 八进制 十六进制 0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 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
1919
Base Sixteen: Another Base Used by Designers
Nice because each position represents four base-two positions Compact way to write binary numbers
Known as hexadecimal, or just hex
Q: Write 11110000 in hex
F 0Q: Convert hex A01 to binary
1010 0000 0001
A:
A:
20
二进制与八进制和十六进制之间的转换位数替换法:保持小数点不变,每位八进制数对 应 3位二进制数 ;
每位十六进制数对应 4位二进制数 ;
二进制转换时,从小数点开始向左右分组,在MSB前面和 LSB后面可以加 0;
转换为二进制时,MSB前面和 LSB后面的 0不写;例: 1011100010112=56138=B8B16
10111000.10112=207.548=B8.B161000110010012 = ( )8
= ( )16
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2121
Hex Example: RFID TagBatteryless (无电池) tag powered(功
率) by radio fieldTransmits (发送) unique
identification(鉴定) numberExample: 32 bit id(身份证明)
8-bit province number, 8-bit city number, 16-bit animal number Tag contents are in binary But programmers use hex when writing/reading
RFIDtag
Province # City # Animal #
Province: 7 City: 160 Animal : 513
1010000000000111 00000010 00000001
A007 02 01
Tag ID in hex: 07A00201
(a)
(b)
(c)
(d)
(f)
(e)
22
2.3 General Positional-Number-System Conversion (常用按位计数制的
转换 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
A Number in any Radix to Radix 10 ( 任意进制数 十进制数 )
Method: Expanding the formula using radix-10 arithmetic (方法:利用位权展开 )
Example 1 : ( 101.01 )2 = ( )10
( 7F.8 )16 = ( )10
More easy way( 更简便的方法 ) ? ( F1AC )16 = ( ( ( F16 ) +1 ) 16 + A ) 16 + C
23
2.3 General Positional-Number-System Conversion (常用按位计数制的转
换 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
A Number in Radix 10 to any Radix ( 十进制 其它进制 )
Method:Radix Multiplication or Division (基数乘除法 )
Integer Parts (整数部分 ):
除 r 取余,逆序排列 Example 2: ( 156 )10 = ( )2 Decimal Fraction Parts (小数部分 ):
乘 r 取整,顺序排列 Example 3: ( 0.37 )10 = ( )2
24
2.3 General Positional-Number-System Conversion (常用按位计数制的
转换 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
Example 4: Require < 10-2 , Complete the
following conversion
( 617.28 )10 = ( )2
2-n <= < 10-2
思考:任意两种进位计数制之间的转换 以十进制(二进制)作为桥梁
n = 7
2525
Converting To/From Binary by Hand: Summary
BinaryDecimal
16 8 4
0 1 0
2 1
1 1
16 + 8 + 2
To decimal
To hex
1 1010
= 2610
= 1A16
To octal
11 010
= 328
2610
To binary
4
0 1
2
0
116
1
8
1
1616+8= 24 24 --24+2
= 26
2626
Divide-By-2 Method Common in Automatic Conversion
Repeatedly divide decimal number by 2, place remainder in current binary digit (starting from 1s column)
1. Divide decimal number by 2 Insert remainder into the binary number Continue since quotient (6) is greater than 0
2. Divide quotient by 2 Insert remainder into the binary number Continue since quotient (3) is greater than 0
01
18
14
02
01
14
02
01
01
02
Decimal Binary
122–12
0
6
62–6
0
3
3. Divide quotient by 2 Insert remainder into the binary number Continue since quotient (1) is greater than 0
32–2
1
1
4. Divide quotient by 2 Insert remainder into the binary number Quotient is 0, done
12–0
1
0
(current value: 12)
(current value: 4)
(current value: 0)
(current value: 0)
Note: Works for any base N—just divide by N instead
2727
Bytes, Kilobytes, Megabytes, and More
Byte: 8 bits
Common metric prefixes: kilo (thousand, or 103), mega (million, or 106), giga (billion, 千兆 or 109), and tera (trillion, 万亿 or 1012), e.g., kilobyte, or KByte
2828
Bytes, Kilobytes, Megabytes, and More
BUT, metric prefixes also commonly used inaccurately216 = 65536 commonly written as “64
Kbyte”Typical when describing memory sizes
Also watch out for “KB” for kilobyte vs. “Kb” for kilobit
2929
Example: DIP-Switch Controlled Channel
Ceiling fan receiver should be set in factory to respond to channel “73”
Convert 73 to binary, set DIP (指拨)switch accordingly
Desired value: 73
4
0 0
2
1
116
0
8
1
32
0
64
1
128
0
64 72 73sum:
(b)(a)
Q:
30
Example: DIP-Switch Controlled Channel
channel receiver
Ceiling fanmodule
0
if (InA = InB) Out = 1else
Out = 0
0 1 0 10 1 0 0"73"
DIP switch
10
0 0 1 00 0 0 1
InA InB
Out
"34"
(c)
31
2.4 Addition and Subtraction of Nondecimal Numbers (非十进制数的加法和
减法 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
Two Binary Number Arithmetic
(两个二进制数的算术运算 )Addition (加法 ): Carry (进位 ) 1 + 1 = 10
Subtraction (减法 ): Borrows (借位 ) 10 – 1 = 1
32
•Carry in ( 进位输入 ): C in (P.32)• Carry out ( 进位输出 ) C out Sum ( 本位和 ): S
2.4 Addition and Subtraction of Non-decimal Numbers ( 非十进制数的加法和减法 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
1011 1110
+ 1000 1101
33
Digital Logic Design and Application ( 数字逻辑设计及应用 )
表 2.3.1 二进制加法真值表
输 入 输 出
被加数 X 加数 Y 输入进位 Cin 和 S 进位输出 Cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
3434
Adder Example: DIP-Switch-Based Adding Calculator
Goal: Create calculator that adds two 8-bit binary numbers, specified using DIP switches
DIP switch: Dual-In-line Package switch, move each switch up or down
Solution: Use 8-bit adder
35
Adder Example: DIP-Switch-Based Adding Calculator
Solution: Use 8-bit adderDIP switches
10
a7……..a0
b7……..b0
s7…………s0
8-bit carry-ripple adderco
ci 0
CALC
LEDs
3636
Adder Example: DIP-Switch-Based Adding Calculator
To prevent spurious( 假的) values from appearing at output, can place register at outputActually, the light flickers( 闪烁) from spurious values would be too fast for humans to detect—but the principle of registering outputs to avoid spurious values being read by external devices (which normally
aren’t humans) applies here.
37
Adder Example: DIP-Switch-Based Adding Calculator
DIP switches
10
a7…….a0
b7……b0
s7………s0
8-bit adder
8-bit register
coci 0
CALC
LEDs
e
clkld
38
•Borrow in ( 借位输入 ): Bin •Borrow out ( 借位输出 ): Bout •Difference bit ( 本位差 ): D
2.4 Addition and Subtraction of Non-decimal Numbers ( 非十进制数的加法和减法 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
1010 1010
– 0101 0101
39
Digital Logic Design and Application ( 数字逻辑设计及应用 )
表 2.3.2 二进制减法真值表输 入 输 出
被减数 X 减数 Y 输入借位 Bin 差 D 输出借位 Bout
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
40
Subtractor Example: DIP-Switch Based
Adding/Subtracting Calculator
Extend earlier calculator exampleSwitch f indicates whether want to add
(f=0) or subtract (f=1)Use subtractor and 2x1 mux
41
Subtractor Example: DIP-Switch Based
Adding/Subtracting CalculatorDIP switches
10
8-bit register CALC
LEDs
e
f
clkld
8
8
80 08
8
8
88 2x10 110
wiciA AB B
S Sco wo8-bit adder 8-bit subtractor
42
2.5 Representation of Negative Numbers
(负数的表示 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.5.1 Signed-Magnitude Representation
[ – 符号 数值表示法(原码) ]MSB as the Sign bit (0 = plus, 1 = minus)
[ 最高有效位表示符号位( 0 = 正, 1 = 负) ]
01111111=+ 127 11111111=- 12700101110=+ 46 10101110=- 4600000000=+ 0 10000000=- 0
43
2.5 Representation of Negative Numbers
(负数的表示 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.5.1 Signed-Magnitude Representation
[ – 符号 数值表示法(原码) ]Two possible representations of Zero
[零有两种表示( + 0 – 、 0) ]An n-bit signed-magnitude integer range is
(n位二进制整数表示范围 ) : – ( 2n-1 – 1) ~ + ( 2n-1 – 1)
44
2.5 Representation of Negative Numbers (负数的表示 )
2.5.2 Complement Number Systems
(补码数制 )
Radix – Complement
(基数补码 )Diminished Radix – Complement
[ 基数减 1 补码 (反码 ) ]
Digital Logic Design and Application ( 数字逻辑设计及应用 )
45
2.5 Representation of Negative Numbers (负数的表示 )
2.5.3 Radix – Complement Representation ( 基数补码表示法 )
The complement of an n-digit number is obtained by subtracting it from r n
(n 位数的补码等于从 r n 中减去该数 )
Example : Table 2-4 P.36
Digital Logic Design and Application ( 数字逻辑设计及应用 )
46
2.5 Representation of Negative Numbers (负数的表示 )
Diminished Radix – Complement Representation
[ 基数减 1补码表示法(反码) ]: The Diminished Radix – Complement
of an n-digit number is obtained by subtracting it from r n -1
[ n 位数的反码等于从 r n – 1 中减去该数 ]
Example : Table 2-4 2-5 P.36
Digital Logic Design and Application ( 数字逻辑设计及应用 )
4747
Ten’s Complement Before introducing two’s
complement, let’s consider ten’s complement But, be aware that computers
DO NOT USE TEN’S COMPLEMENT. Introduced for intuition (直觉) only.
Complements for each base ten number shown to right. Complement is the number that when added results in 10
987654321
123456789
4848
Ten’s Complement Nice feature of ten’s complement
Instead of subtracting a number, adding its complement results in answer exactly 10 too much
So just drop (丢下) the 1 – results in subtracting using addition only
4 6
10
7
–4 +6
0 10 20
3 13
13
3
0 10
1
2
3
4
5
6
7
8
9
9
8
7
6
5
4
3
2
1
complements
7–4=3 7+6=13 3Adding the complement results in an answer that isexactly 10 too much – dropping the tens column givesthe right answer.
49
2.5.4 Two’s – Complement Representation (二进制补码表示法 )
The MSB of a number in this system serves as the sign bit(最高有效位用做符号位 );The weight of the MSB is -2n-1 instead of + 2n-1
(MSB的权是 -2n-1 而不是 + 2n-1 )
Obtain a Two’s- Complement
( 二进制补码的求取 ): Ones’ – Complement (反码 ) + 1 (Why??)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
50
2.5.4 Two’s – Complement Representation (二进制补码表示法 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
例 2.5.1 若约定字长是一个字节,试求- 119的补码。
解:因- 119的绝对值 119= 01110111,则补码可以通过下式算法得到:
全 1 码: 1 1 1 1 1 1 1 1
减去- 119 绝对值: 0 1 1 1 0 1 1 1 - 119 的反码: 1 0 0 0 1 0 0 0 加 1 : 1
- 119 补码: 1 0 0 0 1 0 0 1
51
2.5.4 Two’s – Complement Representation
(二进制补码表示法 )
Only one representations of Zero ( 零只有一种表示 )
0= 0 0 0 0 0 0 0 0 逐位取反 1 1 1 1 1 1 1 1 + 1
约定 8 位 0 0 0 0 0 0 0 0= 0
Digital Logic Design and Application ( 数字逻辑设计及应用 )
52
2.5.4 Two’s – Complement Representation (二进制补码表示法 )
An n-bit Two’s- Complement range is (n位二进制补码表示范围 ): – 2 n-1 ~ + ( 2 n-1 – 1)
约定字长( 8比特)后,补码表示数的范围- 128~ 127
Digital Logic Design and Application ( 数字逻辑设计及应用 )
53
2.5.4 Two’s – Complement Representation (二进制补码表示法 )
Positive number has the same :Sign-Magnitude, Ones’ – Complement, and Two’s- Complement
( 正数的原码、反码、补码相同 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
54
表 2-6 1 位十进制数与 4 位二进制数十进制 二进制原码 二进制反码 二进制补码
-8—— ——
1000-7 1111 1000 1001-6 1110 1001 1010-5 1101 1010 1011-4 1100 1011 1100-3 1011 1100 1101-2 1010 1101 1110-1 1001 1110 11110 1000 或 0000 1111 或 0000 00001 0001 0001 00012 0010 0010 00103 0011 0011 00114 0100 0100 01005 0101 0101 01016 0110 0110 01107 0111 0111 0111
55
2.5 Representation of Negative Numbers (负数的表示 )
2.5.6 Ones’ – Complement Representation
(二进制反码表示法 )
The Sign Bit doesn’t change, Other Bits converse based on the Signed-Magnitude. (符号位不变,其余在原码基础上按位取反 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
5656
Representing Negative Numbers: Two’s Complement
Big advantage: Allows us to perform subtraction using addition
Thus, only need adder component, no need for separate subtractor component
57
Two’s Complement Subtractor Built with an
AdderUsing two’s complement
A – B = A + (-B)
= A + (two’s complement of B)
= A + invert_bits(B) + 1So build subtractor using adder by
inverting B’s bits, and setting carry in to 1
58
Two’s Complement Subtractor Built with an
Adder
1Cin
BA
Adder
S
BA
N-bit
59
Summary of this class (本堂课小结 )
Binary, Octal, and Hexadecimal Numbers
(二进制、八进制、十六进制 )
Positional Number System
( 按位计数制 )
1p
ni
ii rdD
Digital Logic Design and Application ( 数字逻辑设计及应用 )
60
General Positional-Number-System
Conversion
(常用按位计数制的转换 )
A Number in any Radix to Radix 10 : Expanding
the formula using radix-10 arithmetic
( 任意进制数 十进制数:利用位权展开 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )Summary of this class (本堂课小结 )
61
General Positional-Number-System
Conversion
(常用按位计数制的转换 )
A Number in Radix 10 to any Radix : Radix
Multiplication or Division
( 十进制 其它进制:基数乘除法 )
Note: Decimal Fraction Parts Conversion
[ 注意:小数部分的转换(误差) ]
Digital Logic Design and Application ( 数字逻辑设计及应用 )Summary of this class (本堂课小结 )
62
Addition and Subtraction of Nondecimal Numbers (非十进制的加法和减法 ) ( Table 2-3)
进位输入 Cin 、进位输出 Cout 、 本位和S
借位输入 Bin 、借位输出 Bout 、 本位差D
Digital Logic Design and Application ( 数字逻辑设计及应用 )Summary of this class (本堂课小结 )
63
Representation of Negative Numbers (负数的表示 )
Signed-Magnitude [ 符号-数值(原码) ]
Complement Number Systems (补码数制 )
Radix – Complement (基数补码 )
Diminished Radix – Complement
[ 基数减 1补码(基数反码) ]
Digital Logic Design and Application ( 数字逻辑设计及应用 )Summary of this class (本堂课小结 )
64
Binary Signed-Magnitude, Ones’ – Complement, and Two’s – Complement Representation
(二进制的原码、反码、补码 )
正数的原码、反码、补码表示相同
负数的原码表示:符号位为 1
负数的反码表示:
符号位不变,其余在原码基础上按位取反
在 |D| 的原码基础上按位取反(包括符号位)
负数的补码表示:反码 + 1
Digital Logic Design and Application ( 数字逻辑设计及应用 )Summary of this class (本堂课小结 )
65
第 2章作业( P50~ 52)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.1 (e) (i) 2.2 (e) 2.3 (e) 2.4 2.5 (e) (j) 2.6 (f) 补充:
(125.17)10=?2
2.7 (a)
2.8 (a)
2.9 (b)
2.10 (c)
2.11 +25 – 42
2.18 (b) (d)
2.19
66
A Class Problem
Write the 8-bit Signed-magnitude, Two’s-complement, and One’s- complement for each of these decimal numbers:
+115 -100
Digital Logic Design and Application ( 数字逻辑设计及应用 )
67
Chapter 2 Number Systems and codes (数系与
编码 )
Numeric Data - Number Systems and their Conversions
( —— 数值信息 数制及其转换) Nonnumeric Data - Codes
( —— 非数值信息 编码)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
68
Review of Chapter 2 (第二章内容回顾 )
Binary, Octal, and Hexadecimal Numbers
(二进制、八进制、十六进制 )
Positional Number System
( 按位计数制 )
1p
ni
ii rdD
Digital Logic Design and Application ( 数字逻辑设计及应用 )
69
Review of Chapter 2 (第二章内容回顾 )
General Positional-Number-System
Conversion
(常用按位计数制的转换 )
A Number in any Radix to Radix 10 : Expanding
the formula using radix-10 arithmetic
( 任意进制数 十进制数:利用位权展开 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
70
Review of Chapter 2 (第二章内容回顾 )
General Positional-Number-System
Conversion
(常用按位计数制的转换 )
A Number in Radix 10 to any Radix : Radix
Multiplication or Division
( 十进制 其它进制:基数乘除法 )
Note: Decimal Fraction Parts Conversion
[ 注意:小数部分的转换(误差) ]
Digital Logic Design and Application ( 数字逻辑设计及应用 )
71
Review of Chapter 2 (第二章内容回顾 )
Addition and Subtraction of Nondecimal Numbers (非十进制的加法和减法 ) ( Table 2-3)
进位输入 Cin 、进位输出 Cout 、 本位和S
借位输入 Bin 、借位输出 Bout 、 本位差D
Digital Logic Design and Application ( 数字逻辑设计及应用 )
72
Review of Chapter 2 (第二章内容回顾 )
Representation of Negative Numbers (负数的表示 )
Signed-Magnitude [ 符号-数值(原码) ]
Complement Number Systems (补码数制 )
Radix – Complement (基数补码 )
Diminished Radix – Complement
[ 基数减 1补码(基数反码) ]
Digital Logic Design and Application ( 数字逻辑设计及应用 )
73
Review of Chapter 2 (第二章内容回顾 )
Binary Signed-Magnitude, Ones’ – Complement, and Two’s – Complement Representation
(二进制的原码、反码、补码 )
正数的原码、反码、补码表示相同
负数的原码表示:符号位为 1
负数的反码表示:
符号位不变,其余在原码基础上按位取反
在 |D| 的原码基础上按位取反(包括符号位)
负数的补码表示:反码 + 1
Digital Logic Design and Application ( 数字逻辑设计及应用 )
74
2.5.4 Two’s – Complement Representation (二进制补码表示法 )
An n-bit Two’s- Complement range is (n位二进制补码表示范围 ): – 2 n-1 ~ + ( 2 n-1 – 1) Only one representations of Zero
( 零只有一种表示 ) Obtain a Two’s- Complement
( 二进制补码的求取 ): Ones’ – Complement (反码 ) + 1 (为什
么??)Expanding the Sign Bit ( 符号位扩展 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
75
2.5 Representation of Negative Numbers (负数的表示 )
Example 2.5.2:Write the 8-bit signed-magnitude, two’s-complement for each of these binary numbers.
(分别写出下面二进制数的 8 –位符号 数值码、补码 )
( – 1101 )2
( – 0 . 1101 )2
Digital Logic Design and Application ( 数字逻辑设计及应用 )
76
2.5 Representation of Negative Numbers (负数的表示 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
1 、 ( – 1101 )2
2 、 ( – 0 . 1101 )2
1 、 5 位二进制表示: 原码 反码 补码1 1101 1 0010 1 0011
2 、 8 位二进制表示: 原码 反码 补码1000 1101 1111 0010 1111 0011
[ [ D ] 反 ] 反 = D[ [ D ] 补 ] 补 = D
77
2.6 Two’s – Complement Addition and Subtraction (二进制补码的加法和减
法 )Addition Rules: Added by ordinary binary
addition (加法:按普通二进制加法相加 )P.39Subtraction Rules: Taking its two’s
complement, then add
(减法:将减数求补,再相加 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
78
2.6 Two’s – Complement Addition and Subtraction (二进制补码的加法和减
法 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
+ 2 0010 - 3 1101 + + 5 + 0101 + - 5 + 1011 + 7 0111 - 8 11000 + 7 0111 + 1 0001 + - 4 + 1100 + - 6 + 1010 + 3 10011 - 5 1011
7979
Adder/Subtractor Example: Calculator
Previous calculator used separate adder and subtractor
DIP switches
10
8-bitregisterCALC
LEDs
e
f
clkld
8
8
80 0
8
8
8
882x10 1
10
wiciA AB B
S Sco wo8-bit adder 8-bit subtractor
8080
Adder/Subtractor Example: Calculator
Improve by using adder/subtractor, and two’s complement numbers
DIP switches10
8-bit register
8-bit adder/subtractorsub
CALC
LEDs
e
S
A Bf
clkld
10
8 8
8
8
81
2.6 Two’s – Complement Addition and Subtraction (二进制补码的加法和减
法 ) Overflow(溢出)如果加法运算产生的和超出了数制表示的范围,则结果发生了溢出( Overflow)。 对于二进制补码,加数的符号相同,和的符号与加数的符号不同。(或者, C in 与 C out 不同) P.41
对于无符号二进制数,若最高有效位上发生进位或借位,就指示结果超出范围。
- 5 1011 + 7 0111 + - 6 + 1010 + + 3 + 0011 - 11 10101 = + 5 + 10 1010 = - 6
Digital Logic Design and Application ( 数字逻辑设计及应用 )
8282
OverflowSometimes result can’t be represented with given
number of bitsEither too large magnitude of positive or negativeEx. 4-bit two’s complement addition of 0111+0001 (7+1=8).
But 4-bit two’s complement can’t represent number >70111+0001 = 1000 WRONG answer, 1000 in two’s
complement is -8, not +8Adder/subtractor should indicate when overflow has
occurred, so result can be discarded
8383
Detecting Overflow: Method 1
For two’s complement numbers, overflow occurs when the two numbers’ sign bits are the same but differ from the result’s sign bit If the two numbers’ sign bits are initially different, overflow is impossible
Adding positive and negative can’t exceed largest magnitude positive or negative
0 1 1 1
1 0 0 0
+ 00 0 1
sign bits
overflow(a)
1 1 1 1
0 1 1 1
+ 01 0 0
overflow(b)
1 0 0 0
1 1 1 1
+ 10 1 1
no overflow(c)
If the numbers’ sign bits have the same value, whichdiffers from the result’s sign bit, overflow has occurred.
8484
Detecting Overflow: Method 2
Even simpler method: Detect difference between carry-in to sign bit and carry-out from sign bit
0 1 11 1 1
1
10 010 0 0
+ 00 0 1
overflow(a)
1 1 10 0 0
1
0 1 1 1
+ 01 0 0
overflow(b)
1 0 00 0 0
0
1 1 1 1
+ 10 1 1
no overflow(c)
If the carry into the sign bit column differs from thecarry out of that column, overflow has occurred.
85
2.10 Binary Codes for Decimal Numbers
(十进制数的二进制编码 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
A set of n-bit strings in which different bit strings
Represent different numbers or other things.
( 用于表示不同数或其它事件的一组 n 位二进制码的集合 )
86
2.10 Binary Codes for Decimal Numbers
(十进制数的二进制编码 )
How to represent a 1-bit Decimal number with a 4-bit Binary code
( 如何用 4 位二进制码 表示 1位十进制码 )?
—— Binary Coded Decimal (BCD码)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
87
2.10 Binary Codes for Decimal Numbers
(十进制数的二进制编码 )
How to represent a Negative BCD number
(负的 BCD数如何表示 )?Signed-Magnitude Representation: Encoding
of the sign bit is arbitrary
(符号-数值表示:符号位的编码任意 )10’s-complement: 0000 indicates plus, 1001
indicates minus.
(十进制补码表示: 0000正, 1001负 )
Addition of BCD Digits (BCD数的加法 ) P.50
Digital Logic Design and Application ( 数字逻辑设计及应用 )
88
Digital Logic Design and Application ( 数字逻辑设计及应用 )
01011001
11100110
0100
10001000
00000110
0110
59
14
10
88
16
10+
++
++
+ +
4 1
+6
1
1
修正
修正
01000101
1001
10011001
00100110
1000
45
9
99
18
10+
++
+ +
+8
1
1
修正
89
2.10 Binary Codes for Decimal Numbers
(十进制数的二进制编码 ) (Table 2-9)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
BCD Code2421 CodeExcess-3 (余 3码 )Biquinary Code (二五混合码 )1-out-of-10 (10中取 1码 )
Weighted Code ( 加权码 )
Self-Complement Code 自反码
90
Digital Logic Design and Application ( 数字逻辑设计及应用 )
0000
十进制数字
000100100011010001010110011110001001
101010111100110111101111
0000000100100011010010111100110111101111
010101100111100010011010
0011010001010110011110001001101010111100
000000010010110111101111
0100001010001001001000101000011000010000011000010100010010010001010000
00000000000001000001000000110000101
…
1000000000010000000000100000000001000000000010000000000100000000001000000000010000000000100000000001
00000000000000000011000000010100000001100000000111
…
0123456789
BCD(8421)码 2421码 余3码 二五混合码 10中取1码
未用的码字
91
8421 code
Natural code , just like 4-bit
binary numbers;
Each digit is weighted;
It has 10 valid code words
and 6 invalid code words.
BCD codes
92
Each digit is weighted;
Self-complementing;
Use MSB to express
higher/lower part;
It has 10 valid codes and
6 invalid codes.
2421 codes
BCD codes
93
BCD codes
Excess-3 code
Its digit is not weighted;
8421 code + “0011”;
Self-complementing .
94
Examples:
use BCD code for decimal numbers A = 1946
8421 code : A = 0001 1001 0100 0110
2421 code : A = 0001 1111 0100 1100
Excess-3 code: A = 0100 1100 0111 1001
BCD codes
95
1-out-of-10 code
One hot code:
It is very useful in
control systems.
One hot codes
96
Two hot codes
Biquinary code
7-bits; two hot code;
First 2 bits is one hot code for higher/lower range;
Last 5 bits is one hot code in the range.
Error-detecting property !
97
From one code to
its neighbor, only
one bit changed, no
transition state.
Temperature code
98
2.11 Gray code(格雷码)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
110
101
100 011
000111
001
010
0 0 1
101
111
110 010
000100
001
011
0 0 1
99
2.11 Gray code(格雷码)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
特点:任意相邻码字间只有一位数位变化最高位的 0和 1只改变一次最大数回到 0也只有一位码元不同
110
101
100 011
000111
001
010
0 0 1
101
111
110 010
000100
001
011
0 0 1
100
2.11 Gray code(格雷码)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
构造方法直接构造 The bits of an n-bit binary cord word are
numbered from right to left, from 0 to n-1. [ 对 n 位二进制的码字从右到左编号( 0 ~ n-1) ] Bit i of a Gray-code code word is 0 if bits i and
i+1 of the corresponding binary code word are the same, else bit i is 1.
( 若二进制码字的第 i 位和第 i + 1 位相同,则对 应的格雷码码字的第 i 位为 0,否则为 1。 )
Reflected Code(反射码)
101
Gray codes
Target: code for continues changed numbers (in
binary system) to prevent wrong code happened
in transition time;
Property : In each pair of successive code words,
only one bit changes.
102
Gray codes
From binary number to Gray code
The width is same, the MSB is same;
From left to right, if a bit in binary number is same
as its left bit, the gray code is 0, if it is different, the
gray code is 1.
Examples:
binary number: 1001 0010 0110 0011
Gray codes: 1101 1011 0101 0010
103
Error-detecting code
Information word + checking bit
104
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.12 Character Codes (字符编码 ) ASCII码( P36 表 2-11)
ASCII code: 128 Keyboard signs , 7-
bit
Used for keyboard or display device
105
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.13 Codes for Actions, Conditions, and States
(动作、条件和状态的编码 ) 使用 b 位二进制编码来表示 n 个不同状态
Word: a digital string to represent an object
Use n bits, we can make 2n different words;
To make n words, you must use bits. n2log
106
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.16 Codes for Serial Data Transmission and Storage
(用于串行数据传输与存储的编码 )
Parallel way
use n-line to transmit an n-bits code words ;
transmit an n-bits code words in one time period;
Serial way
use one line to transmit an n-bits code words ;
transmit an n-bits code words in n time period;
107
Digital Logic Design and Application ( 数字逻辑设计及应用 )
第 2 章 掌握重点正数的十进制、二进制、八进制、十六进制表示,以及它们之间的相互转换
符号数的 S-M码、补码、反码表示,以及它们之间的相互转换;
带符号数的补码的加减运算 :溢出的判断
BCD码、 GRAY码:表示方法、特点
108
第 2章作业( P75~ 78)
Digital Logic Design and Application ( 数字逻辑设计及应用 )
2.12 (b) (c) 2.34 2.35 2.38 2.39 2.22(选做 ) 2.30 (选做 ) 2.51 (选做 )
109
Chapter 3 Digital Circuits (数字电路 )
Give a knowledge of the Electrical aspects of Digital Circuits
(介绍数字电路中的电气知识 )
Digital Logic Design and Application ( 数字逻辑设计及应用 )
110
Consider some Questions(思考几个问题 )
在模拟的世界中如何表征数字系统?如何将物理上的实际值 映射为逻辑上的 0 和 1 ?什么时候考虑器件的逻辑功能; 什么时候考虑器件的模拟特性?
Digital Logic Design and Application ( 数字逻辑设计及应用 )
111
A Class Problem ( 每课一题 )
Indicate whether or not overflow occurs when adding the following 8-bit two’s-complement numbers:
Digital Logic Design and Application ( 数字逻辑设计及应用 )
1101 0100
+ 1010 1011
0010 0110
+ 0101 1010