Java Reference
In-Depth Information
ber, minus one. For example, the one's complement of the binary number
101 (5 decimal) can be calculated as follows:
1000B = 2 3 = 8 decimal
111B = 1000B minus 1 = 7 decimal
- 101B
5 decimal
-----
---------
010B =
2 decimal
Note that the one's complement can also be obtained by changing ev-
ery 1 binary digit to a 0 and every 0 binary digit to a 1. In the above exam-
ple, 010B is the one's complement of 101B. In this context the 0 binary
digit is often said to be the complement of the 1 binary digit, and vice
versa.
An interesting side effect is that the two's complement can be derived
byaddingonetotheone'scomplementofanumber.Therefore,insteadof
calculating
100000B
- 10110B
-------
01010B
we can find the two's complement of 10110B as follows
10110B = number
01001B = change 0 to 1 and 1 to 0 (one's complement)
+
1B
then add 1
--------
01010B = two's complement
A third way of calculating the two's complement is subtracting the op-
erand from zero and discarding the overflow.
One advantage of numeric complements is that the high-order bit can
be used to detect the sign of the number. Another advantage is that there
is no representation for negative 0.
Representing Fractional Numbers
Inapositionalnumbersystemtheweightofeachintegerdigitcanbedeter-
mined by the formula:
PdB
C
Search WWH ::




Custom Search