Start here · Essential guide
Shift Operators in C++
Learn how the << and >> shift operators work in C++, with binary examples, compound forms, precedence traps, undefined cases, and safe ways to use them.
Syntax and Functions
How left and right shifts move bits, with small examples like 1 << n.
Start here · Essential guide
Learn how the << and >> shift operators work in C++, with binary examples, compound forms, precedence traps, undefined cases, and safe ways to use them.
Learn what >>= means in C and C++: it right-shifts a variable's bits and stores the result back, the same as x = x >> n. See a worked example.
Learn what 1 << 1 does in C: it shifts the bits of 1 one place left, giving 2. See the binary steps, a program, and the precedence trap in C and C++.
Learn what 1 << n means in C: it shifts a single bit left n places, giving 2 to the power of n. See the valid range, bit masks, and when to use a wider type.
Related topics