Integer Shift Operations in C++ If you want to write reliable, portable and future-proof c++ code, you should base your creativity on what's explicitly defined in the language standard. Behaviours which are implementation-defined or even undefined should not be exploited, even though they seem to work as intuitively expected, even across platforms. The integer bitwise shift operations are a good example. The underlying hardware often provides instructions for all combinations of left/right, int/long, signed/unsigned shifts. That fuels the perception of "the compiler will select the correct instruction, no matter what". This perception is often fulfilled, but in no way covered by the language standard. So, what does the standard cover after all? Unsigned types: left shift works "as expected", bits that fall "off the cliff" on the left are lost. right shift works "as expected", bits that fall "off the cliff" on the right are lost. Signed types: left shift of positive values works "as expected", bits are discarded before they enter the sign position. right shift of positive values works "as expected", bits that fall "off the cliff" on the right are lost. left shift of negative values is undefined. right shift of negative values in implementation-defined. Shift amount: must be non-negative and smaller than the number of bits in the left operand, otherwise behaviour is undefined. All information herein is based on: https://en.cppreference.com/w/cpp/language/operator_arithmetic