Java Reference
In-Depth Information
01011101 binary = 93 decimal
11011101 binary = -93 decimal
|
|—————————- sign bit
Note that the left-most digit is set for a negative number and clear for a
positiveone.Thiswayofdesignatingnegativenumbers,calleda sign-mag-
nitude representation, corresponds to the conventional way in which we
write signed numbers longhand. That is, we precede the number by its
sign. Sign-magnitude representation has the following characteristics:
1. The absolute value of positive and negative numbers is the same.
2. Positive from negative numbers can be distinguished by examining the
high-order bit. If this bit is 1, then the number is negative. Otherwise, the
number is positive.
3. Therearetwopossiblerepresentationsforzero,onenegative(10000000B)
and one positive (00000000B).
One limitation of the sign-magnitude representation is that the logic re-
quired to perform addition is different from that for subtraction. While this
is not insurmountable, there are other numeric representations (discussed
later in this chapter) in which addition and subtraction are a single opera-
tion. Another limitation of straight sign-magnitude representations is the
presence of negative zero. The negative zero reduces the numerical range
of the representation and is unnecessary for most practical purposes.
Thelimitationsofthesign-magnitudeformatcanbeseeninthecompli-
cated rules required for the addition of signed numbers. Assuming two
signed operands, x and y, the following rules must be observed for per-
forming addition:
1. If x and y havethesamesign,theyareaddeddirectlyandtheresultisgiven
the common sign of the addends.
2. If the absolute value of x is larger than or equal to the absolute value of y ,
then y is subtracted from x and the result is given the sign of x .
3. Iftheabsolutevalueof y islargerthantheabsolutevalueof x ,then x issub-
tracted from y and the result is given the sign of y .
4. If both x and y are -0, then the sum is 0.
The rules for subtracting numbers in sign-magnitude form are even
more complicated.
Search WWH ::




Custom Search