 Download Download Presentation Number Systems

# Number Systems

Download Presentation ## Number Systems

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Number Systems

2. Why binary numbers? • Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). • Digital designer should be familiar with: • binary math. • Conversion between binary and other number systems. • Also how real life numbers, events and conditions can be expressed in using binary numbers.

3. Coding information in binary form Digital System processing information in binary form. Decode information from binary form Why binary numbers?

4. Common Number systems

5. Positional Number Systems • In general, a number D of base r is of the form d2d1d0has the value: D = d2.r2 + d1.r1 + d0.r0 • decimal number 747 of base 10 is of the form 747 = 7.102 + 4.101 + 7.100 747 = 7.100+ 4.10+ 7.1 747 = 700+ 40+ 7 747 = 747

6. Binary Number System • In general, a number D of base r is of the form d2d1d0 has the value: D = d2.22 + d1.21 + d0.20 • binary number 101 of base 2 is of the form 101 = 1.22 + 0.21 + 1.20 101 = 1.4+ 0.2+ 1.1 101 = 4+ 0+ 1 101 = 5

7. fraction • In general, a number D of base r is of the form d2d1d0.d-1d-2 has the value: D = d2.r2 + d1.r1 + d0.r0 .d-1.r-1 + d-2.r-2 747.25 = 7.102 + 4.101 + 7.100 . 2.10-1 + 5.10-2 747.25 = 7.100+ 4.10+ 7.1 . 2.0.1+ 5.0.01 747.25 = 700+ 40+ 7 . 0.2+ 0.05 747.25 = 747.25

8. Radix point D = d2.r2 + d1.r1 + d0.r0 .d-1.r-1 + d-2.r-2 • in binary number system it is called binary point • in decimal number system it is called decimal point General form: D = dp-1.rp-1 + … + d1.r1 + d0.r0 .d-1.r-1 + d-2.r-2 + … + d-n.r-n

9. Convention of writing different number systems

10. p-1 di.ri D = i = -n Conversions • Radix r to decimal conversion: where, p digits on the left side of the radix point and n digits on the right side of the radix point Summation of the positional values of all digits.

11. Nested expansion formula • Radixrto decimal conversion: D = ((...((dp-1).r+dp-2).r +...).r + d1).r + d0 e.g., 101 = ((1).2+0).2 + 1 101 = (2+0).2 + 1 101 = (2).2 + 1 101 = 4 + 1 101 = 5

12. decimal to radix r conversion D = ((...((dp-1).r+dp-2).r +...).r + d1).r + d0 to convert a decimal number to radix r number divide the decimal number by randtheremainderwillbethed0(LSB). Successive divisions by r yield successive digits of Dr from right to left (LSB to MSB, d2 d1 d0). e.g., 5/2 = 2 remainder 1 (d0 ,LSB) 2/2 = 1 remainder 0 (d1) 1/2 = 0 remainder 1 (d2 ,MSB) 5 = 101 (d2 d1 d0)

13. Octal and Hexadecimal numbers • Base 10 or decimal numbers we use everyday. • Base 2 or binary numbers are processed directly by digital circuits. • Base 8 or octal and • Base 16 or hexadecimal numbers we use for convenient representation of multibit binary numbers in a digital system. e.g., the I/O addresses of a serial communication port COM1 is 03F8 ~ 03FF instead of 0000 0011 1111 1000 ~ 0000 0011 1111 1111 0 3 F 8 ~ 0 3 F F

14. Conversion of Octal and Hexadecimal numbers to and from Binary numbers: • Bits in a binary numbers are grouped in 3s and substitute with octal symbols and vise versa: 10000011  10 000 011  010 000 011 binary 2 0 3 octal • Bits in a binary numbers are grouped in 4s and substitute with hexadecimal symbols and vise versa: 10000011  1000 0011 binary 8 3 hexdecimal

15. Addition of non-decimal numbers addition and subtraction of nondecimal numbers by hand uses the same technique that we learned in our childhood but we use different tables.

16. Subtraction of non-decimal numbers A very common use of subtraction in computers is to compare two numbers. If X-Y produces a borrow out of MSB position, then X is less than Y.

17. Subtraction of non-decimal numbers using decimal 1st method: • convert non-decimal numbers to decimal • calculate results, and • convert back. 2nd method: • each column addition (or subtraction) can be done by converting the column digits to decimal, • adding in decimal, and • converting the result to corresponding sum and carry digits in the non-decimal number. (A carry is produced whenever the column sum equals or exceeds the radix.)

18. Representation of negative numbers: • Signed-Magnitude Representation • Complement number systems • radix-complement • diminished radix-complement Most computers and other digital systems use the two’s complement system to represent negative numbers.

19. Signed-magnitude Representation A number consists of a magnitude and a symbol indicating whether the magnitude is positive or negative. e.g., +15 and -15 0000 1111 and 1000 1111 The signed-magnitude number system has an equal number of positive and negative integers, and there are two possible representations of zero. e.g., +0 and -0

20. Signed-magnitude binary numbers The signed-magnitude system is applied to binary numbers by using an extra bit position to represent the sign (the sign bit). The MSB is used as the sign bit ( 0 = plus, 1=minus), and the rest is for magnitude. An n-bit signed-magnitude integer lies within the range-(2n-1-1) through +(2n-1-1), and there are two possible representations of zero. e.g., 0000 0000 and 1000 0000

21. Signed-magnitude Representation • Suppose we wanted to build a digital circuit that adds signed-magnitude numbers. • The circuit must examine the signs of the addends to determine what to do with the magnitudes. • If the signs are the same, it must add the magnitudes and give the result the same sign. • If the signs are the different, it must compare the magnitudes, subtract the smaller from the larger, and give the result the sign of the larger. • All of these “ifs”, “adds”, “subtracts”, and “compares” translate into a lot of logic-circuit complexity. • Adders for complement number systems are much simpler.

22. Complement number systems • While the signed-magnitude system negates a number by changing its sign, a complement number system negates by taking its complement. • In a Complement number system two numbers can be added or subtracted directly without the sign and magnitude checks.

23. Two complement number systems • Radix complement - two’s complement • Diminished radix-complement - one’s complement • In any complement number system, we normally deal with a fixed number of digits, say n. • if an operation produces a result that requires more than n digits, we through away the extra high-order digit(s). • If a number D is complemented twice, the result is D.

24. Radix-complement representation • The complement of an n-digit number is obtained by subtracting it from rn. (rn - D) Examples using 4-digit decimal numbers: complement of 0007 is (104 - 7) or 9993 and is known as 10’s complement.

25. ‘0’ in radix-complement • radix complement of D is (rn - D) • radix complement of 1 is (rn - 1) (10n - 1) = 99...99 • radix complement of 0 is (rn - 0) (10n - 0) = 100…00 there are (n+1) digits = 00…00 (n digits) we throw away the extra high-order bit and the result is 0. Thus, there is only one representation of zero.

26. Computing the radix-complement • It seems from the definition that a subtraction operation is needed to compute the radix complement of D. • this subtraction can be avoided by rewriting rn as (rn -1)+1and (rn-D) as ((rn-1)-D)+1) if we define the complement of a digit d to be (r-1)-d, then (rn-1)-D is obtained by complementing the digits of D. (2n-D) as (1’s complement)+1) (10n-D) as (9’s complement)+1) The number (rn -1) has the form mm … mm, where m = r-1 (104 -1)= 9999 (24 -1) = 1111

27. Digit complements for different number systems

28. Two’s-complement representation • For binary numbers, the radix complement is called the two’s complement. • The MSB serves as a sign bit. • The decimal equivalent for a two’s complement binary number is computed the same way as for an unsigned number, except that the weight of the MSB is -(2n-1) instead of +(2n-1). e.g., -5 = 1111 1011 = 1.(-27)+ 1.26 + 1.25 + 1.24 + 1.23 + 0.22 + 1.21 + 1.20 = 1.(-128)+ 1.64+ 1.32+ 1.16+ 1.8+ 0.4+ 1.2+ 1.1 = -128 + 64+ 32+ 16+ 8+ 0+ 2+ 1 = -128 + 123 = -5

29. Two’s-complement representation • The range of representable numbers is -(2n-1) through +(2n-1 -1) e.g., 5 = 0000 0101 one’s complement is 1111 1010 two’s complement is 1111 1010 + 1 = 1111 1011 = -5 • zero is considered positive because its sign bit is 0. • There is no negative zero we end up with one extra negative number, -(2n-1), that does not have a positive counterpart.

30. Extending a two’s-complement number • We can convert an n-bit two’s-complement number into an m-bit one, where m > n. • we append m-n copies of the sign bit to the left. • That is we pad a positive number with 0s anda negative one with 1s; this is called sign extension. e.g., 5 = 0101 5 = 0000 0101 -5 = 1011 -5 = 1111 1011

31. Reducing a two’s-complement number • We can convert an n-bit two’s-complement number into an m-bit one, where n>m only when n-m leftmostbits are the same. • Otherwise this exercise is meaningless. • We discard n-m copies of the leftmostbits . e.g., 5 = 0000 0101 5 = 0101 -5 = 1111 1011 -5 = 1011

32. Diminished radix-complement representation • The complement of an n-digit number D is obtained by subtracting it from rn-1. ~D = (rn-1)-D • This can be accomplished by complementing the individual digits of D. When n=1, ~d = (r-1)-d = (9-1)-7 = 2 • in decimal it is called 9’s complement • in binary it is called 1’s complement examples: complement of 0007 is ((104 -1)- 0007) or, (9999-0007) or, 9992 complement of 1011 is ((24 -1)- 1011) or, (1111-1011) or, 0100

33. Examples of the diminished radix-complement • The complement of an n-digit number D is obtained by subtracting it from rn-1. ((rn-1)-D) • if n=1 ((rn-1)-D) becomes ((r-1)-D) and is the complement of single digit D e.g., D=0, so complement of D is ((r-1)-D) i.e., in binary system it is ((2-1)-0)=1 i.e., in decimal system it is ((10-1)-0)=9 • The number (rn -1) has the form mm … mm, where m = r-1 (104 -1)= 9999 (24 -1) = 1111

34. Converting One’s-complement to decimal • A weight of -(2n-1-1) , rather -(2n-1) , is given to the MSB when computing the decimal equivalent. • Thus there are two zeros: positive zero = 00...00 negative zero = 11…11 • The range of numbers is: -(2n-1 -1) through +(2n-1 -1) • Advantage: numbers are symmetric and ease of complementation • Disadvantage: Adder design is trickier, need to resolve two zeros.

35. Two’s complement Addition • By ordinary addition, ignoring any carries beyond the MSB. • Ordinary addition is just an extension of counting, two’s complement numbers. • As long as the result is not exceeded the range.

37. Two’s complement Subtraction • Negate the subtrahend (number to be subtracted) by taking its two’s complement, and then add it to the minuend (number from which the subtrahend is to be subtracted) using the normal rules for addition. • Negating the subtrahend and adding the minuend can be accomplished with only one addition operation.

38. One’s complement Addition & Subtraction • Same as two’s complement except if there is a carry out of the sign position add 1 to the result. Because there are two zeros. • To do one’s-complement subtraction complement the subtrahend and add.

39. Summary of Addition & Subtraction

40. Binary Multiplication • Shift-and-add multiplication: Same as we learned in school to multiply by adding a list of shifted multiplicands computed according to the digits of the multiplier. • In a digital system it is more convenient to add each shifted multiplicand as it is created to a partial product. • The Shift-and-add algorithm can be performed by a digital circuit that includes a shift register, an adder, and control logic.

41. Binary signed multiplication • Multiplication of signed numbers can be accomplished usingunsigned multiplication. • Make the product positive if the operands had the same sign. • Make the product negative if the operands had the different signs.

42. Binary Division • Shift-and-subtract division: we mentally compare the reduced dividend with multiples of the divisor to determine which multiple of the shifted divisor to subtract. • In binary case the shifted divisor has only two choices - 0 and the divisor itself.

43. Binary signed division • Division of signed numbers can be accomplished usingunsigned division . • Make the quotient positive if the operands had the same sign. • Make the quotient negative if the operands had the different signs.