Number System
08/23/152
08/23/153
08/23/154
08/23/155
08/23/156
08/23/157
08/23/158
08/23/159
08/23/1510
08/23/1511
08/23/1512
08/23/1513
08/23/1514
08/23/1515
08/23/1516
08/23/1517
08/23/1518
08/23/1519
08/23/1520
08/23/1521
08/23/1522
08/23/1523
08/23/1524
08/23/1525
08/23/1526
08/23/1527
08/23/1528
08/23/1529
08/23/1530
08/23/1531
08/23/1532
r’s and r-1’s COMPLEMENTS
 USED FOR
 SIMPLIFY SUBTRACTION OPERATIONS
 TWO TYPES
Decimal Binary Octal Hexadecimal
 r’ s complement 10’s 2’s 8’s 16’s
 r - 1’s complement 9’s 1’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
 r-1’s Complement
 SUBSTRACT EVERY DIGIT FROM r-1
Note: r’s Complement=r-1’s Complement +1
34
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
10’s Complement Examples
35
-003
+1
↓↓↓
996
997
-214
+1
↓↓↓
785
786
Example #1
Example #2
Complement Digits
Add 1
Complement Digits
Add 1
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)
08/23/1536
Example
08/23/1537
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.
08/23/1538
08/23/1539
08/23/1540
08/23/1541
08/23/1542
08/23/1543
BINARY ARITHMETIC OPERATION
08/23/1544
BINARY ADDITION EXAMPLE
08/23/1545
BINARY ARITHMETIC OPERATION (Cont…)
08/23/1546
We have already discussed these two.
BINARY SUBTRACTION EXAMPLE
08/23/1547
08/23/1548
OCTAL ARITHMETIC OPERATION
08/23/1549
08/23/1550
08/23/1551
08/23/1552
08/23/1553
08/23/1554
08/23/1555
08/23/1556
08/23/1557
08/23/1558
Flowchart for steps in C program Execution
Practice problems
1. Given the binary number 11011011, what is its decimal value if it
is a
a. unsigned binary number
b. Signed binary number
c. 2's complement number
2. Convert +24 into a 2's complement number
08/23/1559
Ans: 219
Ans: -37
Ans: -37
Ans: 011000 Note the leading zero!
3. Convert -24 into a 2's complement number
4. Convert -1 into a 2's complement number (assume a 4-bit result)
5. What is the minimum (maximum negative) number which can be
represented using a 6-bit 2's Complement representation? What is the
maximum (positive) number?
08/23/1560
Ans: 1111
Ans: 101000
Ans: +31, -32
Practice problems (Cont…)
Practice problems (Cont…)
Convert, if possible, the following decimal numbers to 2's
complement assuming an 8-bit binary representation for all.
i. 1 = ii. -1 =
iii. 72 = iv. 127 =
v. -127 = 10000001 vi. -105 = 10010111
vii. 255 = viii. -255 =
ix. -6 =
08/23/1561
00000001 11111111
01001000 01111111
Not Possible
11111010
Not Possible
Practice problems (Cont…)
Convert the following 2's complement numbers to decimal.
i. 1111 = ii. 11110000 =
iii. 001101 = iv. 11111111 = -1
v. 0000000 = 0 vi. 01 = 1
08/23/1562
-1 -16
13
08/23/1563
08/23/1564
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.
08/23/1565
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.
08/23/1566
#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.
08/23/1567
08/23/1568

8 number-system

Editor's Notes

  • #36 Examples of the 10’s Complement Process.