Pages: [1]   Go Down
Author Topic: Bitshift and two's complement in the documentation  (Read 564 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

While reading the documentation for the Bitshift operation I struggled over:
Quote
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:

Quote
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.

/Iterationbound

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)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31343
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8430
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Better men than us have tried and failed smiley

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: