Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 232© 2005 JW Ryder1 Bases  324 10 = (3 * 10 2 ) + (2 * 10 1 ) + (4 * 10 0 )  324 8 = (3 * 8 2 ) + (2 * 8 1 ) + (4 * 8 0 )  1011 2 = (1 * 2 3 )

Similar presentations


Presentation on theme: "CSCI 232© 2005 JW Ryder1 Bases  324 10 = (3 * 10 2 ) + (2 * 10 1 ) + (4 * 10 0 )  324 8 = (3 * 8 2 ) + (2 * 8 1 ) + (4 * 8 0 )  1011 2 = (1 * 2 3 )"— Presentation transcript:

1 CSCI 232© 2005 JW Ryder1 Bases  324 10 = (3 * 10 2 ) + (2 * 10 1 ) + (4 * 10 0 )  324 8 = (3 * 8 2 ) + (2 * 8 1 ) + (4 * 8 0 )  1011 2 = (1 * 2 3 ) + (0 * 2 2 ) + (1 * 2 1 ) + (1 * 2 0 )  Hexadecimal is base (radix) 16  Uses 0-9, A-F  (Able, Baker, Charlie, Dog, Easy, Fox)  Binary  Hex conversions

2 CSCI 232© 2005 JW Ryder2 Complements  2 types of complements for every base r  r's complement  (r - 1)'s complement  2's and 1's complement for binary, 10's and 9's complement for decimal

3 CSCI 232© 2005 JW Ryder3 (r - 1)'s Complement  Given a number N in base r having n digits, the (r - 1)'s complement of N is defined as (r n - 1) – N  If r = 10, r-1 = 9's complement so 9's complement of a decimal number N is (10 n - 1) - N

4 CSCI 232© 2005 JW Ryder4  10 n is a number with a single 1 followed by n 0's  10 n -1 is a number with n 9's  n = 5; 10 n = 100000 and 10 n -1 = 99999  9's complement of a decimal number is obtained by subtracting each digit from 9 r-1 Complement

5 CSCI 232© 2005 JW Ryder5  9's complement of 123456 is: 999999 - 123456  9-6=3, 9-5=4, 9-4=5, 9-3=6, 9-2=7, 9-1=8 (876543) 9’s Complement

6 CSCI 232© 2005 JW Ryder6 One's Complement  1's complement obtained in same way r = 2, (r - 1) = 1  1's complement of N is (r n - 1) - N  (2 n - 1) - N  n = 4, N = 0110, r n = 10000, (r n - 1) = 1111  n largest digits that can be held in a radix r digit

7 CSCI 232© 2005 JW Ryder7 Number N 1's Complement  N 1’s Complement  0011 1100  0000 0000 1111 1111  1010 0101 0101 1010  1101 1000 0010 0111  Do you notice anything?  (2 4 -1) - 3 = 12 in decimal

8 CSCI 232© 2005 JW Ryder8 Answer  1's complement formed by changing 1's to 0's and vice versa

9 CSCI 232© 2005 JW Ryder9 r's Complement  r's complement is (r - 1)'s complement + 1  [(r n - 1) - N] + 1 = r n - N  10's complement of decimal 8793 is 1206 + 1 = 1207  Guess what? 8793 + 1207 = 10000  1 plus by n 0's  8793 + 1206 = 9999  n 9's in a row

10 CSCI 232© 2005 JW Ryder10  Formed by  leaving all least significant 0's unchanged  subtracting first non-zero digit from 10  subtracting the rest of the digits from 9 8793 original number 1207 10's complement 10’s Complement – Quick Way

11 CSCI 232© 2005 JW Ryder11 2's Complement – Quick Way  Works same as 10's complement  2's complement of a number N is r n - N  2's complement of 1100 0011 is  2 8 - (1100 0011)  1 0000 0000 - 1100 0011 = 0011 1101

12 CSCI 232© 2005 JW Ryder12 Quick Form – 2’s Complement  Moving right to left  Keep all least significant 0's and the first 1 encountered unchanged  Complement rest of digits moving left through the most significant digit

13 CSCI 232© 2005 JW Ryder13 Subtraction of Unsigned Numbers  Elementary school method does not work out well for digital computers  Subtraction of 2 n-digit unsigned numbers M - N where N is not equal to 0 is done as follows:  Add minuend M to the r's complement of the subtrahend N.  This performs M + (r n - N)

14 CSCI 232© 2005 JW Ryder14  If M >= N, the sum will produce an end carry r n which is discarded, and what is left is the result M - N  If M < N, the sum does not produce an end carry. It is equal to the r's complement of (M - N).  The correct answer is generated by  taking the r's complement of the answer  then adding a negative sign to the front Subtraction

15 CSCI 232© 2005 JW Ryder15 Example with Positive Answer  Example (M >= N) 72532 - 13250 = 59282 10's complement of 13250 is 86750  M (minuend) = 72532  10's complement of N (subtrahend) is 86750  Sum = 72532 + 86750 = 159282  YES a carry out. Positive result. Scratch high order 1. Answer = 59282

16 CSCI 232© 2005 JW Ryder16 Example with Negative Answer  Example (M < N) 13250 - 72532 = - 59282  M (minuend) = 13250  10's complement of N (subtrahend) is 27468  Sum = 13250 + 27468 = 40718  NO carry out! This means negative number!

17 CSCI 232© 2005 JW Ryder17 Example with Negative Number  Take  10's complement of 40718 which is 59282  add a negative sign to the front  Answer is -59282

18 CSCI 232© 2005 JW Ryder18 2’s Complement Subtraction  Example 2's complement (X >= Y)  X = 1010100 Y = 1000011  2's complement of Y is 0111101  X (minuend) = 1010100  2's complement of Y (subtrahend) is 0111101  Sum = 1010100 + 0111101 = 1 0010001  YES a carry out. Positive result. Scratch high order 1. Answer (X-Y) is 0010001

19 CSCI 232© 2005 JW Ryder19 Negative Result Example  Example 2's complement (Y - X)  Y = 1000011 X = 1010100  2's complement of X is 0101100  Y (minuend) = 1000011  2's complement of X (subtrahend) is 0101100  Sum = 1000011 + 0101100 = 1101111  NO carry out! Negative result.

20 CSCI 232© 2005 JW Ryder20 Negative Result Example  Take  2's complement of 1101111 which is 0010001  add a negative sign to the front  Answer is - 0010001


Download ppt "CSCI 232© 2005 JW Ryder1 Bases  324 10 = (3 * 10 2 ) + (2 * 10 1 ) + (4 * 10 0 )  324 8 = (3 * 8 2 ) + (2 * 8 1 ) + (4 * 8 0 )  1011 2 = (1 * 2 3 )"

Similar presentations


Ads by Google