Bit shifting and assignment

bit-shift, c, c++

Solution

Undefined behavior occurs when you shift a value by a number of bits which is not less than its size (e.g, 32 or more bits for a 32-bit integer). You've just encountered an example of that undefined behavior.

Problem

This is sort of driving me crazy. ``` int a = 0xffffffff; int b = 32; cout << (a << b) << "\n"; cout << (0xffffffff << 32) << "\n"; ``` My output is ``` -1 0 ``` Why am I not getting ``` 0 0 ```

Original source

Related problems