So, I remembered hearing in school that the C++ spec didn't define whether or not a bitwise right-shift was done with an arithmetic or a logical shift (sar and shr for the x86 people). Well, turns out this is partially right. Here's the relevant clause:
Clause 5.8.3:
The value of E1 >> E2 is E1 right shifted E2 bit positions. If E1 has an
(
Read more... )
Comments 3
Reply
Reply
I know from experience that >> doesn't mean "either logical or arithmetic depending on context". It's always the same command, if you check the assembly. I think the representation of negative numbers (two's complement, one's complement, sign bit, etc.) is implementation-dependent, making the logical shift operator result for negative numbers unspecifiable by the standard. (Except to say that it's gonna be the value, bit-shifted to the right, whatever that turns out to be.)
Reply
Leave a comment