Bit shifting
Bit shifting is a bitwise operation that moves the positions of an integer’s binary digits left or right by a specified count.
100 Java Mistakes and How to Avoid Them
A bitwise shift operator moves the binary representation of an integer left or right by a specified number of bit positions.
- How it is used
- Uses shifts for packing values, masks, flags, and compact bit-vector manipulation.
- How deep it goes
- Explains precedence, modulo shift counts, result typing, and concrete masking corner cases.
- Examples
- Uses value packing, a handwritten hashCode, buffer sizing, a least-significant-bit mask, and a long field bit setter.
- What you can do after
- Diagnose/debug with it by checking grouping, shift-count boundaries, and left-operand types in Java expressions.
Read how 100 Java Mistakes and How to Avoid Them explains bit shifting →
Modern C
A shift operation is a C bitwise operation that moves the bits of an integer representation left or right by a specified operand.
- How it is used
- Uses unsigned shifts to move through bit sets, specify powers of two, and build enumeration masks.
- How deep it goes
- Explains bit movement, arithmetic correspondence, discarded bits, precision constraints, and signedness, without resolving negative signed shifts.
- Examples
- Works through A = 240, overflowed left shifts, right-shift remainders, and named enumeration masks.
- What you can do after
- Apply it via C shift operators to calculate powers of two, manipulate bit sets, and define flag masks.
Related concepts
- plus operatorcontrasts with · The plus operator is a language-defined operation, commonly performing numeric addition, string concatenation, or collection combination according to operand types.
- precisionconfigured by · Numerical precision is the fineness with which a numerical representation or computation distinguishes and retains values.
- operatorkind of · An operator is a symbol, keyword, or language construct that specifies an operation on one or more operands.
- right-shift operationincludes · A bitwise operation that moves an integer’s bits toward less-significant positions, with vacated and shifted-out bits handled according to the operation’s semantics.
- left-shift operationincludes · A left-shift operation moves an integer’s bits toward more-significant positions by a specified number of places, handling discarded bits according to the operation’s semantics.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

