Reputation: 709
I am reading computer architecture by Carl Hamacher. The following lines are confusing me
If we use a 32-bit binary number to represent a signed integer in 2's complement then the range of values that can be represented is
-2^31 to 2^31 - 1
. //fineThe same 32-bit patterns can be interpreted as fractions in the range
-1 to +1 - 2^-31
if we assume that the implied binary point is just to the right of the sign bit.
I don't understand how the range has been calculated for the fraction. I myself calculated the range for positive fractions with the highest fraction being 2^31-1
. But I am unable to calculate the lowest value (mentioned as -1).
Upvotes: 0
Views: 97
Reputation: 241701
Shifting the binary point is tantamount to dividing by a power of two. So if we shift the binary point 31 positions, we are effectively representing fractions whose denominators are 231 and whise numerators are the unshifted integers. Thus the range becomes -231/231 to (231-1)/231, which is -1 to 1-2-31.
Another way to look at it: In 2's complement integer representation, the bit positions have weights (left to right) of -231, 230, 229, …, 20 (where only the first weight is negative). Shifting the binary point to just after the high-order (and negated) bit -- "the sign bit" -- makes rhe weights -20, 2-1, 2-2, …, 2-31 (again, only the first weight is negative). Again, it's clear that the "most negative" is 100…0, which has the value -1, the weight for the only one-bit
Upvotes: 2