530 likes | 635 Views
Chapter 2. Number Systems and Codes. Preface. Why discuss Numbers and Codes. Numerical value. Codes. Multiplex temperature detecting system. Kn.=(knot). Quipu. The Shang Dynasty (Inscriptions on bones or tortoise shells) -Decimal Numbers. ?. 100. 1000. 10000. 70. 80. 200. 300.
E N D
Chapter 2 Number Systems and Codes
Preface Why discuss Numbers and Codes Numerical value Codes Multiplex temperature detecting system
Kn.=(knot) Quipu
The Shang Dynasty (Inscriptions on bones or tortoise shells) -Decimal Numbers
? 100 1000 10000 70 80 200 300 400 500 600 20 30 40 50 60 800 900 2000 3000 4000 5000 8000 30000
Rome Numbers I, V, X, L, C, D, M 1,5,10,50,100,500,1000
2.1Positional Number Systems × × × 30 102 20
1.Radix-r-to-decimal D :Position i’s Weight Base Digit
2.Binary-to-decimal ·The binary radix is normally used to represent numbers in a digital system!
MSB LSB Ex.2-1 10010.112= 1 0 0 1 0 ×24+ ×23+×22+×21+ ×20 .1 1 ×2-1+ ×2-2 =18.7510
3.Binary-to-octal and hexadecimal ·For reading, writing and remembering Ex . 2-2 Binary Document Octal Document Hexadecimal Document
Ex.2-3 0 10111011001.11001012 0 0 . 2 7 3 1 6 2 4 8
Ex.2-4 0 10111011001.11001012 0 . 5 D 9 C A 16
Octal-to-Binary Ex.2-5 2 7 3 1 . 6 2 48 . 0 10 111 011 001 110 010 1 00 2
Hexadecimal-to-Binary Ex.2-6 5 D 9 . C A 16 . 0 101 1101 1001 1100 101 0 2 4bit-----nibble(One hexadecimal number) 8bit-----byte(Two hexadecimal numbers)
LSD ÷r Quotient= ÷r Remainder=d0 Quotient= ÷r Remainder=d1 MSD Quotient=0 Remainder=dp-1
×r Product= Fraction= ×r Integer=d-1 Product= Fraction= Integer=d-2 … Precision d-1 d-2 d-3
Ex.2-7 61859.89916992187510=( ? )16 ÷16 ÷16 ÷16 ÷16 15 0 61859 3866 241 (10) A Remainder: 1 3 (15) F ×16 0.899169921875 14.38671875 ×16 Integer: (14)E 0.38671875 6.1875 Integer: 6 ×16 0.1875 3 Integer: 3 Ans: F1A3.E6316
Radix-r1-to-Radix-r2 Radix-r1 Decimal Radix-r2 Homework: P74 2.1 2.3 2.5 2.6 2.19
2.2 Addition and Subtraction of Nondecimal Numbers 1. Addition of Binary Numbers Ex.2-8 1 1 1 1 1 1 C 101111102 19010 X Y + 14110 + 100011012 3 3 1 10 1 0 1 0 0 1 0 1 1 2
2.Addition of Hexadecimal Numbers Ex.2-9 1 1 1 C 19010 X BE16 Y + 14110 + 8D16 33110 1 4 B 16
3.Subtraction of Binary Numbers Ex.2-10 B 1 1 1 1 1 1 33110 1010010112 X Y - 14110 - 100011012 1 9 0 1 1 1 1 1 0 1 0 10 2
4.Subtraction of Hexadecimal Numbers Ex.2-11 B 1 1 1 33110 X 14B16 Y - 14110 - 8D16 1 9 0 E 10 B 16
X-Y ( If X and Y are positive.) Ex.2-12 No B X>Y 1 14110 X Yes Y - 33110 X-Y Y-X ? 1 0 Result is positive (+) Result is negative (-)
2.3 Representation of Negative Numbers ■Signed-Magnitude Representation ■Radix-Complement Representation ■Two’s-Complement Representation ■Diminished Radix-Complement Representation ■Ones’-Complement Representation
1.Signed-Magnitude Representation -10510 +32110 Sign Sign -1011012 +1100012 Sign Sign 01100012 11011012 Digital systems have just only two states! 0=plus(+) Sign bit MSB 1=minus(-)
2.Radix-Complement Representation D: n-digit number Fixed If then
2 digit decimal numbers Positive numbers Negative numbers … … … +0 +1 +2 +3 +4 … +48 +49 -50 -49 -5 -4 -3 -2 -1 Ex.2-13 14Complement 1410 + 82Complement - 1810 9 6 Complement 1410+(-1810) (-410)
n=2 Ex.2-14 1 1 -1410 86Complement 1810 + 18Complement + -1410+1810 0 4 1 Complement Ex.2-15 1 -1410 86Complement 1810 + 82Complement - -1410+(-1810) 1 6 8 Complement (-3210)
Ex.2-16 4310 43Complement 4510 + + 45Complement 8810 8 8 Complement (-1210) Overflow Range: Range:[-50,49] Two’s-Complement
3.Dinimished Radix-Complement Representation D: n-digit number Fixed
2 digit decimal numbers Positive numbers Negative numbers … … … +0 +1 +2 +3 +4 … +48 +49 -49 -48 -4 -3 -2 -1 -0 Range: Two zeros:+0 and -0 Range:[-49,49] Ones’-Complement
4.Two’s-Complement Addition and Subtraction Range:[-2n-1,2n-1-1] 4bit 0000 1111 0001 0010 1110 +0 1 +1 2 +2 0011 1101 -1 3 +3 1100 4 +4 0100 +1 5 +5 0101 1011 6 +6 7 +7 8 1010 0110 1001 0111 MSB weight:-2n-1 Overflow 1000
Ex.2-17 4bit C C 1 1 1 X +3 X -2 0011 1110 Y + +4 + 0100 Y + -6 + 1010 0 +7 0 1 1 1 -8 1 1 0 0 C C 1 1 X +6 X +4 0110 0100 Y + -3 + 1101 Y + -7 + 1001 1 +3 0 0 1 1 -3 1 1 0 1
Range:[-8,+7] Ex.2-18 4bit C C 1 1 X -3 X +5 1101 0101 Y + -6 + 1010 Y + +6 + 0110 1 -9 1 0 1 1 1 +11 1 0 1 =-5 =+7 C C 1 1 1 1 X -8 X +7 1000 0111 Y + -8 + 1000 Y + +7 + 0111 0 -16 0 0 0 0 +14 1 1 1 1 =+0 =-2 Overflow: The result out of range!
Rules for detecting overflow: ■Addition of two numbers with different signs can never produce overflow! ■If the addends’ signs are same but the sum’s sign is different from the addends’. ■If the carry bits cin into and cout out of the sign position are different. √ MSB
Subtraction Rules: ■Do not perform subtraction directly! ■Negating the subtrahend, and then add it to the minuend using normal rules for addition.( Initial carry cin=1) Ex.2-19 4bit C C 1 1 1 1 1 1 X +4 X +3 0100 0011 Y - +3 + - 0011 1100 Y - -4 + - 1100 0011 1 +1 0 0 0 1 +7 0 1 1 1
5.Ones’-Complement Addition and Subtraction Range:[-(2n-1-1),2n-1-1] 4bit 0000 -1 1111 0001 +1 0010 1110 +0 0 +1 1 +2 0011 1101 -1 2 +3 1100 3 +4 0100 +1 4 +5 0101 1011 5 +6 6 +7 7 1010 0110 1001 0111 MSB weight:-(2n-1-1) Overflow 1000
4bit End-around carry Ex.2-20 Range:[-7,+7] C 1 C X -2 1101 ■Rules for detecting overflow are same as two’s-complement! X +3 0011 Y + -5 + 1010 Y + +4 + 0100 1 -7 1 0 1 1 +7 0 1 1 1 1 1 1 + 1 ■Subtraction Rule: Negating the subtrahend, and then add it to the minuend using normal rules for addition.( Initial carry cin=0) 1 1 0 0 0 C 1 1 C 1 X +6 0110 X -3 1100 Y + -3 + 1100 Y + -5 + 1010 +3 0 0 1 0 1 0 -8 1 0 1 1 1 + 1 + 1 1 1 0 0 1 1 1 1 0 Overflow
Homework: P75 2.7 2.10 2.11 2.12 The three systems have the same positive numbers. Two’s-Complement System P40 Table 2-6 Sign-Magnitude System Ones’-Complement System
6. Sign extension 0 0 0 0 0010 1 0 0 0 0010 1 1 1 1 1010 0 0 0 0 0010 0 0 0 0 0010 1 1 1 1 1010
7.Signed Fractional and Floating-Point (13.3) 16bit Fixed Point Signed Fractional Format 15 14 13 4 3 2 1 0 … -212 211 210 21 20 2-1 2-2 2-3 Radix Point IEEE 32bit Single-Precision Floating Point Format 31 30 23 22 2 1 0 … … s f2 f1 f0 e7 e0 1.f22 Sign bit Hidden bit Binary Point
2.4 Binary Codes Not weighted code Weighted code Self-complementing 1.BCD
2. Addition of 8421BCD Ex.2-21 1 1 0101BCD 0100BCD 5 4 1001BCD 0101BCD + + + 9 + 5 1 1 1 1 0 14 1 1 0 9 1 0 1 BCD 0110 + Carry 1 0 0 0 BCD If a result exceeds 1001, the result is corrected by adding 6.
3.Gray Code 001 010 001 011 001 001 000 011