Wrong solution for exercise 2.2(b)?

I feel like there’s something wrong with this solution. First of all, if I’m not mistaken, I am meant to represent possibly negative numbers [b]/4 with unsigned bit strings b’ (<b’>), which already confuses me. And even if I interpret the solutions as signed bit strings, for each solution except the second one where the initial number [b] is not negative, I get a number that is 1 off. That’s because in the cases where [b] is negative, the solutions are actually rounded up instead of down. Am I missing something or should the solutions be

111100
000100
111011
000000

because that’s what I get.
Or well, if you use the method that is described in the solution (see image), which in itself does make sense, you at least have to be aware that in negative cases the solution is rounded up instead of down.

Thanks in advance.

Screenshot

1 Like

Hey there,

you are right, the exercise contains a fault.
It should be like that:
image

But then, the answers should be correct!
-19/4 is -5 and so on.

We will fix this on the sheet!

Thank you!

4 Likes

Hey,
adding to @Luise.Puhl’s answer:
The exercise should read: [b'] = \left\lfloor \frac{[b]}{4} \right\rfloor.
For the rounding this is now consistent. For example consider:

[101101] = -19 \\ [110110] = -10 = \lfloor -9.5 \rfloor = \left\lfloor\frac{-19}{2} \right\rfloor = \left\lfloor\frac{[b]}{2} \right\rfloor \text{ (one signed right shift)}\\ [111011] = -5 = \lfloor -4.75 \rfloor = \left\lfloor\frac{-19}{4} \right\rfloor = \left\lfloor\frac{[b]}{4} \right\rfloor \text{ (two signed right shifts)}\\

Hope this helps,
Tim

5 Likes

Oh no, I forgot that rounding negatives goes in the other direction, I’m sorry :laughing::person_facepalming:

Now everything makes sense, thank you both very much!

2 Likes

The corrected version is now online :partying_face:

2 Likes

Indeed, when dividing signed numbers by shifting right, the result is rounded towards -\infty.

When we consider only positive real numbers, the rounding modes we have are \lceil \cdot \rceil, which rounds up (towards +\infty) and \lfloor \cdot \rfloor, which rounds down. Now for non-negative numbers, rounding towards 0 and towards -\infty are the same operation. But for negative numbers, you basically got three rounding modes (towards +\infty, 0, or -\infty), since 0 und -\infty differ on negative numbers.

Sadly, we don’t have good notation that makes this precise, so it is easy to confuse.

1 Like