Go Down

Topic: Bitshift and two's complement in the documentation (Read 1 time) previous topic - next topic


Well, I am new here and this is my first post, please be not to harsh if I missed some forum rules ;)

While reading the documentation for the Bitshift operation I struggled over:
In that case, the sign bit is copied into lower bits, for esoteric historical reasons:

I'm unhappy with that since two's complement is neither historic nor esoteric - nearly every processor implements negative integers this way. Injecting the one for negative numbers keeps them negative and makes sure that division by powers of two for negative numbers works as expected. One could argue that this might be to deep into number representation theory, but a few lines later exactly this division is shown:

If you are careful to avoid sign extension, you can use the right-shift operator >> as a way to divide by powers of 2. For example:

Here it gets completely unhelpful: you are told to avoid the sign but in reality everything just works, due to the injected one.

My proposal: drop "for esoteric historical reasons", and mention that the injected ones guarantee proper results for negative numbers in the bottom.


P.S. (Maybe it would be nice to have a page on number representation anyway where it would be possible to get deeper into the details)


I'm unhappy with that since two's complement is neither historic nor esoteric

Yes I quite agree with you.
However experience shows that it is hard if not imposable to correct mistakes in that area of the site.


Better men than us have tried and failed :)

Rob Gray aka the GRAYnomad www.robgray.com

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131