Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.

Similar presentations


Presentation on theme: "Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer."— 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 Why binary numbers? Digital System processing information in binary form. Coding information in binary form Decode information from binary form

4 Common Number systems

5 Positional Number Systems In general, a number D of base r is of the form d 2 d 1 d 0 has the value: D = d 2. r 2 + d 1. r 1 + d 0. r 0 decimal number 747 of base 10 is of the form 747 = 7. 10 2 + 4. 10 1 + 7. 10 0 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 d 2 d 1 d 0 has the value: D = d 2. 2 2 + d 1. 2 1 + d 0. 2 0 binary number 101 of base 2 is of the form 101 = 1. 2 2 + 0. 2 1 + 1. 2 0 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 d 2 d 1 d 0. d -1 d -2 has the value: D = d 2. r 2 + d 1. r 1 + d 0. r 0. d -1. r -1 + d -2. r -2 747.25 = 7. 10 2 + 4. 10 1 + 7. 10 0. 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 = d 2. r 2 + d 1. r 1 + d 0. r 0. 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 = d p-1. r p-1 + … + d 1. r 1 + d 0. r 0. d -1. r -1 + d -2. r -2 + … + d -n. r -n

9 Convention of writing different number systems

10 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. p-1 i = -n di.ridi.ri D =

11 Nested expansion formula Radix r to decimal conversion: D = ((... ((d p-1 ). r +d p-2 ). r +... ). r + d 1 ). r + d 0 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 = ((... ((d p-1 ). r +d p-2 ). r +... ). r + d 1 ). r + d 0 to convert a decimal number to radix r number divide the decimal number by r and the remainder will be the d 0 (LSB). Successive divisions by r yield successive digits of D r from right to left (LSB to MSB, d 2 d 1 d 0 ). e.g., 5/2 = 2 remainder 1 (d 0,LSB) 2/2 = 1 remainder 0 (d 1) 1/2 = 0 remainder 1 (d 2,MSB) 5 = 101 (d 2 d 1 d 0 )

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 3F8 ~ 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

16

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

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

19 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.)

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

21 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

22 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 -(2 n-1 -1) through +(2 n-1 -1), and there are two possible representations of zero. e.g., 0000 0000 and 1000 0000

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

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

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

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

27 ‘0’ in radix-complement radix complement of D is (r n - D) radix complement of 1 is (r n - 1) (10 n - 1) = 99...99 radix complement of 0 is (r n - 0) (10 n - 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.

28 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 r n as (r n -1)+1 and (r n -D) as ((r n -1)-D)+1) if we define the complement of a digit d to be (r-1)-d, then (r n -1)-D is obtained by complementing the digits of D. (2 n -D) as (1’s complement)+1) (10 n -D) as (9’s complement)+1) The number (r n -1) has the form mm … mm, where m = r-1 (10 4 -1)= 9999 (2 4 -1) = 1111

29 Digit complements for different number systems

30 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 -(2 n-1 ) instead of +(2 n-1 ). e.g., -5 = 1111 1011 = 1. (-2 7 )+ 1. 2 6 + 1. 2 5 + 1. 2 4 + 1. 2 3 + 0. 2 2 + 1. 2 1 + 1. 2 0 = 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

31 Two’s-complement representation The range of representable numbers is -(2 n-1 ) through +(2 n-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, -(2 n-1 ), that does not have a positive counterpart.

32 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 and a negative one with 1s; this is called sign extension. e.g., 5 = 0101 5 = 0000 0101 -5 = 1011 -5 = 1111 1011

33 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 leftmost bits are the same. Otherwise this exercise is meaningless. We discard n-m copies of the leftmost bits. e.g., 5 = 0000 0101 5 = 0101 -5 = 1111 1011 -5 = 1011

34 Diminished radix-complement representation The complement of an n-digit number D is obtained by subtracting it from r n -1. ~D = (r n -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 ((10 4 -1)- 0007) or, (9999-0007) or, 9992 complement of 1011 is ((2 4 -1)- 1011) or, (1111-1011) or, 0100

35 Examples of the diminished radix-complement The complement of an n-digit number D is obtained by subtracting it from r n -1. ((r n -1)-D) if n=1 ((r n -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 (r n -1) has the form mm … mm, where m = r-1 (10 4 -1)= 9999 (2 4 -1) = 1111

36 Converting One’s-complement to decimal A weight of -(2 n-1 -1), rather -(2 n-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: -(2 n-1 -1) through +(2 n-1 -1) Advantage: numbers are symmetric and ease of complementation Disadvantage: Adder design is trickier, need to resolve two zeros.

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

38 Two’s complement Addition

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

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

41 Summary of Addition & Subtraction

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

43 Binary signed multiplication Multiplication of signed numbers can be accomplished using unsigned multiplication. Make the product positive if the operands had the same sign. Make the product negative if the operands had the different signs.

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

45 Binary signed division Division of signed numbers can be accomplished using unsigned division. Make the quotient positive if the operands had the same sign. Make the quotient negative if the operands had the different signs.


Download ppt "Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer."

Similar presentations


Ads by Google