#include int main(int argc, char** argv) { // 32 bit machine assumed unsigned int x = UINT_MAX; std::cout << "x = UINT_MAX" << std::endl; // binary: 1111 1111 1111 1111 1111 1111 1111 1111 // hex: f f f f f f f f std::cout << "x : " << std::hex << x << std::endl; x = x >> 2; // binary: 0011 1111 1111 1111 1111 1111 1111 1111 // hex: 3 f f f f f f f std::cout << "x >> 2: " << std::hex << x << std::endl; x = x << 1; // binary: 0111 1111 1111 1111 1111 1111 1111 1110 // hex: 7 f f f f f f e std::cout << "x << 1: " << std::hex << x << std::endl; x = x << 2; // binary: 1111 1111 1111 1111 1111 1111 1111 1000 // hex: f f f f f f f 8 std::cout << "x << 2: " << std::hex << x << std::endl; // Notes: // "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" // // There are additional issues to be considered if your left operand // is signed, be sure you understand all the caveats of the standard // and your platform when bit shifting signed values. return 0; }