Number System 2 12162021 3 12162021 4 12162021
Number System
2 12/16/2021
3 12/16/2021
4 12/16/2021
5 12/16/2021
6 12/16/2021
7 12/16/2021
8 12/16/2021
9 12/16/2021
10 12/16/2021
11 12/16/2021
12 12/16/2021
13 12/16/2021
14 12/16/2021
15 12/16/2021
16 12/16/2021
17 12/16/2021
18 12/16/2021
19 12/16/2021
20 12/16/2021
21 12/16/2021
22 12/16/2021
23 12/16/2021
24 12/16/2021
25 12/16/2021
26 12/16/2021
27 12/16/2021
28 12/16/2021
29 12/16/2021
30 12/16/2021
31 12/16/2021
32 12/16/2021
r’s and r-1’s COMPLEMENTS USED FOR SIMPLIFY SUBTRACTION OPERATIONS TWO TYPES r’ s r - 1’s complement Decimal 10’s 9’s Binary 2’s 1’s Octal Hexadecimal 8’s 16’s 7’s 15’s Here r is base or radix of number system r’s Complement LEAVE ALL LSD ZEROS UNCHANGED SUBSTRACT FIRST NONZERO LSD FROM r SUBSTRACT ALL OTHER HIGHER DIGITS FROM r-1’s Complement SUBSTRACT EVERY DIGIT FROM r-1 Note: r’s Complement=r-1’s Complement +1
RULES TO GET COMPLEMENTS 9’S SUBSTRACT EVERY DIGIT FROM 9 Example: 9’s complement of 134795 is 865204 10’s=(9’s complement +1) 10’s complement can be Directly calculated by following steps: LEAVE ALL LSD ZEROS UNCHANGED SUBSTRACT FIRST NONZERO LSD FROM 10 SUBSTRACT ALL OTHER HIGHER DIGITS FROM 9 Example: 10’s complement of 134795 is 865205 Example: find the 9’s and 10’s complements of 314700. 2’S LEAVE ALL LS ZEROS AND FIRST NON ZERO DIGIT UNCHANGED REPLACE 1 BY 0 AND 0 BY 1 IN ALL HIGHER DIGITS 1’S 1 IS CHANGED TO 0 AND 0 IS CHANGED TO 1 Note: COMPLEMENT OF A COMPLEMENT RESTORES THE ORIGINAL VALUE OF THE NUMBER 34
10’s Complement Examples Example #1 -003 996 +1 997 Complement Digits Add 1 Example #2 -214 785 +1 786 Complement Digits Add 1 35
Subtraction using r’s complement: To find M-N in base r, we add M + r’s complement of N 1) If M > N then result is M – N + c (c is an end around carry and Just neglect it. 2) If M < N then result is rn –(N-M) which is the r’s complement of the result. (to get actual number take r’s complement again and put – sign before number) 36 12/16/2021
Example 37 12/16/2021
Subtraction using r-1’s complement The same rules apply to subtraction using the (r-1)’s complements. The only difference is that when an end carry is generated, it is not discarded but added to the least significant digit of the result. Also, if no end carry is generated, then the answer is negative and in the (r-1)’s complement form. 38 12/16/2021
39 12/16/2021
40 12/16/2021
41 12/16/2021
42 12/16/2021
43 12/16/2021
BINARY ARITHMETIC OPERATION 44 12/16/2021
BINARY ADDITION EXAMPLE 45 12/16/2021
BINARY ARITHMETIC OPERATION (Cont…) We have already discussed these two. 46 12/16/2021
BINARY SUBTRACTION EXAMPLE 47 12/16/2021
48 12/16/2021
OCTAL ARITHMETIC OPERATION 49 12/16/2021
50 12/16/2021
51 12/16/2021
52 12/16/2021
53 12/16/2021
54 12/16/2021
55 12/16/2021
56 12/16/2021
57 12/16/2021
Flowchart for steps in C program Execution 58 12/16/2021
Practice problems 1. Given the binary number 11011011, what is its decimal value if it is a a. unsigned binary number Ans: 219 b. Signed binary number Ans: -37 c. 2's complement number Ans: -37 2. Convert +24 into a 2's complement number Ans: 011000 Note the leading zero! 59 12/16/2021
Practice problems (Cont…) 3. Convert -24 into a 2's complement number Ans: 101000 4. Convert -1 into a 2's complement number (assume a 4 -bit result) Ans: 1111 5. What is the minimum (maximum negative) number which can be Ans: +31, -32 represented using a 6 -bit 2's Complement representation? What is the maximum (positive) number? 60 12/16/2021
Practice problems (Cont…) Convert, if possible, the following decimal numbers to 2's complement assuming an 8 -bit binary representation 00000001 for all. 1111 i. 1 = 01001000 ii. 01111111 -1 = iii. 72 = iv. 127 = v. -127 = 10000001 Not Possiblevi. -105 = 10010111 Not Possible vii. 25511111010 = viii. -255 = ix. -6 = 61 12/16/2021
Practice problems (Cont…) Convert the following 2's complement numbers to decimal. -1 i. 1111 = 13 iii. 001101 = v. 0000000 = 0 62 -16 ii. 11110000 = iv. 1111 = -1 vi. 01 = 1 12/16/2021
63 12/16/2021
64 12/16/2021
As a general rule, it is a good idea to avoid the use operators that cause side effects inside of compound expressions. This includes all assignment operators, plus the increment and decrement operators. 65 Note: As a general rule, it is a good idea to avoid the use of operators that alter the value of same variable more than one in the same expression, because this causes side effects. This includes all assignment operators, plus the increment and decrement operators. For all side effects result will be compiler dependent. 12/16/2021
66 12/16/2021
#include<stdio. h> void main() { int i=3; printf("%d", ++i + ++i); o/p 9 for turbo c 10 by codepad } The results are undefined. You're modifying a variable more than once in an expression (or sequence point to be more accurate). Modifying a variable more than once between sequence points is undefined, so don't do it. 67 12/16/2021
68 12/16/2021
- Slides: 68