1 / 111

数字逻辑设计及应用

Digital Logic Design and Application ( 数字逻辑设计及应用 ). 数字逻辑设计及应用. Chapter 2 Number Systems and codes ( 数系与编码 ) 介绍在数字逻辑体系中信号的 表达方式 、 类型 ,不同表达方式之间的 转换 , 运算 的规则等。. Digital Logic Design and Application ( 数字逻辑设计及应用 ). Review of Chapter 1 ( 第一章内容回顾 ).

Télécharger la présentation

数字逻辑设计及应用

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Digital Logic Design and Application (数字逻辑设计及应用) 数字逻辑设计及应用 Chapter 2Number Systems and codes (数系与编码) 介绍在数字逻辑体系中信号的表达方式、类型,不同表达方式之间的转换,运算的规则等。

  2. Digital Logic Design and Application (数字逻辑设计及应用) Review of Chapter 1 (第一章内容回顾) • Analog versus Digital (模拟与数字) • Digital Devices (数字器件): Gates(门电路)、 Flip-flops(触发器) • Electronic and Software Aspects of Digital Design (数字设计的电子技术和软件技术)

  3. Digital Logic Design and Application (数字逻辑设计及应用) Review of Chapter 1 (第一章内容回顾) • Integrated Circuit(IC,集成电路) • Programmable Logic Devices(PLA、PLD、CPLD、FPGA, 可编程逻辑器件) • Application-Specific ICs(ASIC, 专用集成电路) • Printed-Circuit Boards (PCB, 印制电路板)

  4. Digital Logic Design and Application (数字逻辑设计及应用) Chapter 2Number Systems and codes (数系与编码) • Two kinds of Information (信息主要有两类): • Numeric Data (数值信息) • Nonnumeric Data (非数值信息) —Number Systems and their Conversions (数制及其转换) -- Nonnumeric Data Representation – Codes (非数值信息的表征 -- 编码)

  5. Digital Logic Design and Application (数字逻辑设计及应用) Chapter 2Number Systems and codes (数系与编码) • 数字系统只处理数字信号 0 , 1; • 需要将任意信息用( 0 ,1 )表达; • 用(0,1)表达数量: 数制 二进制 • 用(0,1)表达不同对象: 符号编码

  6. How to Encode Text: ASCII, Unicode ASCII: 7- (or 8-) bit encoding of each letter, number, or symbol Sample ASCII encodings … … 6

  7. How to Encode Text: ASCII, Unicode Unicode: Increasingly popular 16-bit encoding Encodes characters from various world languages … … 7

  8. 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 5 2 3 4 3 2 1 0 10 10 10 10 10 • Each position represents a base quantity; symbol in position means how many of that quantity 8

  9. How to Encode Numbers: Binary Numbers Base two (binary) Two symbols: 0 and 1 More than 1 -- next position So each position power(幂) of 2 + = 1 0 1 4 3 2 1 0 2 2 2 2 2 4 + 1 = 5 • Each position represents a base quantity; symbol in position means how many of that quantity Q: How much? a There are only 10 types of people in the world: those who understand binary, and those who don't. 9

  10. Useful to know powers of 2: 9 8 7 6 5 4 3 2 1 0 512 2 256 2 128 2 2 64 2 32 16 2 8 2 4 2 2 2 1 2 Practice counting up by powers of 2: 16 8 2 1 512 256 128 64 32 4 10

  11. Weight of i bit; Base or Radix of r Number System (第i位的权; r 计数制的基数) Digital Logic Design and Application (数字逻辑设计及应用) 2.1 Positional Number System (按位计数制) Any Decimal Number D Can Be Represented as the Following (任意十进制数 D 可表示如下): D = dp-1dp-2 ... d1d0.d-1d-2 ... d-n 推广: D2 = ∑ d i × 2i D16= ∑ d i × 16i

  12. Digital Logic Design and Application (数字逻辑设计及应用) 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)逢基数进一

  13. Digital Logic Design and Application (数字逻辑设计及应用) 2.1 Positional Number System (按位计数制) Decimal and Binary Decimal system: base is 10, the digit may be 0 to 9 Binary system: base is 2, the digit may be 0 or 1 bit: one digit in binary system;

  14. Using Digital Data in a Digital System 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 "33" 0 0 1 0 0 0 0 1 temperature sensor 14

  15. A display converts its ASCII input to the corresponding letter Using Digital Data in a Digital System 1 if (input <= "00100000") // "32" 0 0 1 1 1 0 "33" 0 0 1 0 0 0 0 1 "N" output = "1000110" // "F" else if (input >= "11010100") // "212" output = "1000010" // "B" else output = "1001110" // "N" temperature sensor Digital System N display 15

  16. Digital Logic Design and Application (数字逻辑设计及应用) 2.2 Octal and Hexadecimal Numbers (八进制和十六进制) 基数 数码 特性 Octal Number (八 8 0~7 逢 八 进一 进制) Binary Number (二进制) 2 0,1 逢二进一 Hexadecimal Number(十六进制) 16 0~9,A~F 逢十六进一

  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 十进制、二进制、八进制与十六进制数

  19. 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 0 F Q: Write 11110000 in hex A: Q: Convert hex A01 to binary A: 0001 1010 0000 19

  20. Digital Logic Design and Application (数字逻辑设计及应用) 二进制与八进制和十六进制之间的转换 位数替换法:保持小数点不变,每位八进制数对 应3位二进制数; 每位十六进制数对应4位二进制数; • 二进制转换时,从小数点开始向左右分组,在MSB前面和LSB后面可以加0; • 转换为二进制时,MSB前面和LSB后面的0不写; • 例:1011100010112=56138=B8B16 10111000.10112=207.548=B8.B16 1000110010012 = ( )8 = ( )16

  21. Hex Example: RFID Tag Batteryless(无电池)tag powered(功率) by radio field Transmits(发送) unique identification(鉴定)number Example: 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 (b) Pr o vince # City # Animal # (c) Pr o vince : 7 City : 160 Animal : 513 (a) (d) 00000111 10100000 00000010 00000001 (e) 07 A0 02 01 RFID (f) tag Tag ID in hex: 07A00201 21

  22. Digital Logic Design and Application (数字逻辑设计及应用) 2.3 General Positional-Number-System Conversion (常用按位计数制的转换) • 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 = ( ( ( F16 ) +1 )  16 + A )  16 + C

  23. Digital Logic Design and Application (数字逻辑设计及应用) 2.3 General Positional-Number-System Conversion (常用按位计数制的转换) • 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. Digital Logic Design and Application (数字逻辑设计及应用) 2.3 General Positional-Number-System Conversion (常用按位计数制的转换) Example 4:Require  < 10-2,Complete the following conversion ( 617.28 )10 = ( )2 2-n <= < 10-2  n = 7 思考:任意两种进位计数制之间的转换 以十进制(二进制)作为桥梁

  25. Converting To/From Binary by Hand: Summary 25

  26. Divide-By-2 Method Common in Automatic Conversion Repeatedly divide decimal number by 2, place remainder in current binary digit (starting from 1s column) Note: Works for any base N—just divide by N instead 26

  27. 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 27

  28. Bytes, Kilobytes, Megabytes, and More BUT, metric prefixes also commonly used inaccurately 216 = 65536 commonly written as “64 Kbyte” Typical when describing memory sizes Also watch out for “KB” for kilobyte vs. “Kb” for kilobit 28

  29. 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 0 1 0 0 1 0 0 1 Q: (b) 128 64 32 16 8 4 2 1 (a) sum: 72 73 64 29

  30. Example: DIP-Switch Controlled Channel DIP switch 1 channel receiver 0 1 0 0 0 0 0 "34" 1 0 1 0 0 1 0 "73" 1 0 0 InA InB if (InA = InB) Out = 1 else Out = 0 Ceiling fan module Out (c) 0

  31. Digital Logic Design and Application (数字逻辑设计及应用) 2.4 Addition and Subtraction of Nondecimal Numbers (非十进制数的加法和减法) Two Binary Number Arithmetic (两个二进制数的算术运算) • Addition (加法): Carry (进位) 1 + 1 = 10 • Subtraction (减法): Borrows (借位) 10 – 1 = 1

  32. 1011 1110 + 1000 1101 Digital Logic Design and Application (数字逻辑设计及应用) 2.4 Addition and Subtraction of Non-decimal Numbers (非十进制数的加法和减法) • Carry in (进位输入): C in (P.32) • Carry out ( 进位输出 ) C out • Sum ( 本位和 ): S

  33. Digital Logic Design and Application (数字逻辑设计及应用) 表2.3.1 二进制加法真值表

  34. 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 34

  35. Adder Example: DIP-Switch-Based Adding Calculator Solution: Use 8-bit adder DIP switches 1 0 a7……..a0 b7……..b0 8-bit carry-ripple adder ci 0 co s7…………s0 CALC LEDs

  36. Adder Example: DIP-Switch-Based Adding Calculator To prevent spurious(假的) values from appearing at output, can place register at output Actually, 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. 36

  37. Adder Example: DIP-Switch-Based Adding Calculator DIP switches 1 0 a7…….a0 b7……b0 ci 0 8-bit adder co s7………s0 e ld 8-bit register clk CALC LEDs

  38. 1010 1010 – 0101 0101 Digital Logic Design and Application (数字逻辑设计及应用) 2.4 Addition and Subtraction of Non-decimal Numbers (非十进制数的加法和减法) • Borrow in ( 借位输入 ): Bin • Borrow out ( 借位输出 ): Bout • Difference bit ( 本位差 ): D

  39. Digital Logic Design and Application (数字逻辑设计及应用) 表2.3.2 二进制减法真值表

  40. Subtractor Example: DIP-Switch Based Adding/Subtracting Calculator Extend earlier calculator example Switch 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 Calculator DIP switches 1 0 8 8 8 8 0 0 A B wi A B ci 8-bit subtractor 8-bit adder co S wo S 1 f 8 8 2 x 1 0 1 0 8 e ld 8-bit register CALC clk 8 LEDs

  42. Digital Logic Design and Application (数字逻辑设计及应用) 2.5 Representation of Negative Numbers (负数的表示) • 2.5.1 Signed-Magnitude Representation [符号 – 数值表示法(原码)] • MSB as the Sign bit (0 = plus, 1 = minus) [最高有效位表示符号位( 0 = 正,1 = 负)] • 01111111=+127 11111111=-127 • 00101110=+46 10101110=-46 • 00000000=+0 10000000=-0

  43. Digital Logic Design and Application (数字逻辑设计及应用) 2.5 Representation of Negative Numbers (负数的表示) • 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. Digital Logic Design and Application (数字逻辑设计及应用) 2.5 Representation of Negative Numbers (负数的表示) • 2.5.2 Complement Number Systems (补码数制) • Radix – Complement (基数补码) • Diminished Radix – Complement [ 基数减1补码 (反码) ]

  45. Digital Logic Design and Application (数字逻辑设计及应用) 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

  46. Digital Logic Design and Application (数字逻辑设计及应用) 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

  47. 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 1 9 2 8 3 7 4 6 5 5 6 4 3 7 8 2 9 1 47

  48. 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 3 +6 –4 complements 1 9 10 4 6 2 8 3 7 7 4 6 0 10 20 5 5 3 13 6 4 13 7 3 3 7–4=3 7+6=13 8 2 9 1 Adding the complement results in an answer that is exactly 10 too much – dropping the tens column gives the right answer. 0 10 48

  49. Digital Logic Design and Application (数字逻辑设计及应用) 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??)

  50. Digital Logic Design and Application (数字逻辑设计及应用) 2.5.4 Two’s – Complement Representation (二进制补码表示法) • 例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

More Related