2 Number Systems, Operations, and Codes
Contents Number Systems: Decimal Numbers Binary Numbers Hexadecimal Numbers Binary Arithmetic Code Systems (the principal focus) Binary Coded Decimal (BCD)
2-1 2-2 Number Systems (数制) D= kiNi a. Decimal Number System(十进制) (自学) a. Decimal Number System(十进制) 143.75=1*102+4*101+3*100+7*10-1+5*10-2 D= ki10i b. Binary Number System(二进制) (101.11)2=1*22+0*21+1*20+1*2-1+1*2-2=(5.75)10 D= ki2i D= kiNi 幂的读法 N=Weight(权)
2-3 Decimal-to-Binary Conversion (自学) 情况一:十进制整数 (Whole-Number Conversions) 方法:十进制整数除以2,直到商为0,余数 即为二进制数。 Repeated Division-by-2 Method: Divide the decimal number by 2 until the quotient is 0.Remainders form the binary number.
例: 将十进制数(37)D转换为二进制数。 由上得 (37)D=(100101)B 思考:当十进制数较大时,有什么方法使转换过程简化?
例: 将(133)D转换为二进制数 解:由于27为128,而133-128=5=22+20, 所以对应二进制数b7=1,b2=1,b0=1,其余各系数均为0,所以得 (133)D=(10000101)B
2-3 Decimal-to-Binary Conversion 情况二:十进制小数 (Fractional-Number Conversions) 方法:十进制小数乘以2,直到小数部分为0或直到达到所需的小数位数。 Multiply each resulting fractional part of the product by 2 until the fractional product is 0 or until the desired number of decimal places is reached. Carries produce the binary number. 举例: 1. P22
例 将十进制小数(0.39)D转换成二进制数,要求其误差不大于2-10 0.39×2 = 0.78 b-1= 0 0.78×2 = 1.56 b-2= 1 0.56×2 = 1.12 b-3= 1 0.12×2 = 0.24 b-4= 0 0.24×2 = 0.48 b-5= 0 0.48×2 = 0.96 b-6 = 0 0.96×2 = 1.92 b-7 = 1 0.92×2 = 1.84 b-8 = 1 0.84×2 = 1.68 b-9 = 1 0.68×2 = 1.36 b-10= 1 等效电路由三个基本元件构成 所以
2-4 Binary Arithmetic (二进制的算术运算) Binary addition (二进制加法) The four basic rules for adding binary digits(bits) are as follows: 0+0=0 Sum of 0 with a carry of 0 和为0,进位为0 0+1=1 Sum of 1 with a carry of 0 1+0=1 Sum of 1 with a carry of 0 1+1=10 Sum of 0 with a carry of 1 carry Ex: Add 1010 and 0101.
2-4 Binary Arithmetic (二进制的算术运算) Binary Subtraction(二进制减法) 0-0=0 1-1=0 1-0=1 10-1=1 0-1 with a borrow of 1 (0-1)=11 borrow ex: Subtract 0101 from 1010.
2-4 Binary Arithmetic (二进制的算术运算) Binary multiplication (二进制乘法) 0·0=0, 0·1=0, 1·0=0, 1·1=1 方法:左移被乘数,并进行加法运算。 ex:P25 2-10(学生) 1010 x 0101=?
2-4 Binary Arithmetic (二进制的算术运算) Binary Division (二进制除法) 方法:右移被除数,并进行减法运算。 ex:康华光教材P23:Divide 1010 by 111.
2-10 Binary Coded Decimal (BCD) 二进制编码的十进制码 重点 Code Systems(码制):in digital systems, some codes are used to represent numbers, letters, symbols and instructions. 二进制代码:用一定位数的二进制数码表示文字符号信息,这些数码并不表示数量的大小,仅仅区别不同事物而已。
2-10 Binary Coded Decimal (二-十进制码) BCD code: Binary Coded Decimal a way to express each of the decimal digits with a binary code 4 bits represent each decimal digit. (用4位二进制数代表1位十进制数.) 思考: How many combinations are there?
2-10 Binary Coded Decimal (BCD) Since there are ten digits in decimal system, and there are totally 24=16 combinations for the 4-bits binary, there are some different types to express decimal digits. The 8421 code is the predominant (最主要的) BCD code. 引发出多种BCD码,详见康华光教材P26
Decimal/8421 BCD Conversion Table 2-10-1 The 8421 Code (8421码) The designation 8421 indicates the binary weights(权值) of the four bits (23,22,21,20). Decimal/8421 BCD Conversion Table Decimal Digit 1 2 3 4 8421BCD 0000 0001 0010 0011 0100 5 6 7 8 9 0101 0110 0111 1000 1001
2-10-1 The 8421 Code - Invalid Codes(无效码) With four bits, sixteen numbers (0000 through 1111) can be represented .But in the 8421 code, only ten of these are used. Invalid codes: code combinations that are not used. 1010, 1011, 1100,1101,1110,1111
2-10-1 The 8421 Code - Conversion To express any decimal number in BCD, simply replace each decimal digit with the appropriate 4-bit code. ex. Convert each of the following decimal numbers to BCD: 不能省略! 1个拆成4个
2-10-1 The 8421 Code - Conversion Determine a decimal from a BCD number. Start at the right-most bit and break the code into groups of four bits. Then write the decimal digit represented by each 4-bit group. ex. Convert each of the following BCD codes to decimal : (10000110)BCD=(86)D (111000)BCD=(38)D
2-10-1 The 8421 Code - Difference Difference between 8421BCD code and 4-bite binary code. Ex:(38)D=(111000)BCD =(100110 )B
2-10-2 Some Ordinary BCD Code Systems 8421码 2421 码 5421 码 余3码 余3循环码 0000 0011 0010 1 0001 0100 0110 2 0101 0111 3 4 5 1011 1000 1100 6 1001 1101 7 1010 1111 8 1110 9
2-11 Digital Codes The Gray Code(unweighted 无权码) The important feature : It exhibits only a single bit change from one code word to the next in sequence. (两个相邻代码之间仅有1位取值不同)
详见P50 table 2-5 二进制码 b3b2b1b0 格雷码 G3G2G1G0 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
2-11 Digital Codes b. Advantage : Minimize the chance for error. Ex:从3变成4: 格雷码 二进制码 0010 0011 0110 0100 The three bits are changed . The only one bit is changed . 结论:格雷码可以避免错误数码的出现。
SUMMARE 二进制数 十进制数 转换 二进制数 二进制数的算术运算 数字信号(0,1) BCD码(8421BCD) 二进制代码 格雷码