Shift operators

Hello i am reading an article in topcoder and it says
"When executing shift instructions for a << b, the x86 architecture uses only the bottom 5 bits of b (6 for 64-bit integers). This means that shifting left (or right) by 32 does nothing, rather than clearing all the bits. "
He means that you can shift at most with 31?
The C++ a << b is not defined as "execute the CPU instruction SHL", what that article says is irrelevant.

It is defined as "calculate a*2b" and, for unsigned types, if the result does not fit the result type, "reduce the result modulo maximum value of the return type plus 1"

For 32-bit unsigned types, shifting left by 32 results in zero:

Oh, right, Peter87 is correct: modulo reduction only applies to overflows when right operand is less than 32 in this case
Last edited on
The standard says this about the shift operators.
The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand.
Topic archived. No new replies allowed.