1
$\begingroup$

I am working through the book Computer Systems: A Programmer's Perspective.

The authors explain that round-to-even rounding can be applied for values that are halfway between two possible results. For example, $10.11100_2$ would be rounded up to $11.00_2$ and $10.10100_2$ would be rounded down to $10.10_2$.

In general, they state that only bit patterns of the form $XX...XX...Y100...$, where $X$ denotes arbitrary bit values and $Y$ being the rightmost position to which we round, denote values that are halfway between two possible results.

Could someone explain to me why this is the case?

Thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

Let us express any given binary number without a floating point in the following form $$\underbrace{XX\cdots X}_{i\text{ digits}}~Y~\underbrace{ZZ\cdots Z}_{j\text{ digits}}{}_2=x\times2^{j+1} + Y\times2^j+z $$ where $X$ denotes arbitrary bit values and $Y$ being the rightmost position to which we round. $x$ is the number that corresponds to the first $i$ digits and $z$ is the number that corresponds to the last j digits.

Then two possible results are $$x\times2^{j+1} + Y\times2^j\quad \text{for round-down}$$ $$x\times2^{j+1} + (Y+1)\times2^j\quad\text{for round-up}$$ The average of two possible results, i.e., the number that is half way between them is $$x\times2^{j+1} + Y\times2^j+2^{j-1}$$ which is $$ \underbrace{XX\cdots X}_{i\text{ digits}}~Y1~\underbrace{00\cdots 00}_{j-1\ 0\text{s}}{}_2$$

If there is a floating point in the given binary number, we can multiple it by a power of two to change it to an integer. Run the analysis above. Then divide the same power of two. The bit patterns do not change.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.