Bit Shift Calculator
Calculate logical, arithmetic, and circular bit shifts for 8/16/32/64-bit integers. Visualize binary results with hex, octal, and decimal output.
About
Bit shift errors propagate silently. A single miscalculated shift in an embedded system driver can corrupt register values, cause buffer overflows, or produce hardware faults that cost weeks of debugging. This calculator performs all five shift variants - logical left (SHL), logical right (SHR), arithmetic right (SAR), rotate left (ROL), and rotate right (ROR) - with exact two's complement semantics across 8, 16, 32, and 64-bit widths. Results display in decimal, hexadecimal, octal, and a per-bit binary grid so you can verify each bit position visually.
The tool accepts input in decimal, hexadecimal (0x prefix), binary (0b prefix), or octal (0o prefix) notation. Signed mode interprets values using two's complement representation. Note: shifting by an amount equal to or exceeding the bit width is defined here as producing zero for logical shifts and preserving the sign bit for arithmetic shifts, matching x86 behavior where the shift count is masked to width โ 1 bits. If you need platform-specific wrap semantics, verify against your target ISA manual.
Formulas
Logical left shift multiplies the operand by a power of two, discarding bits that exceed the register width.
where mask = 2w โ 1 and w is the bit width.
Logical right shift fills vacated high bits with zero.
Arithmetic right shift preserves the sign bit via replication.
Rotate left wraps overflow bits from MSB to LSB positions.
Rotate right wraps underflow bits from LSB to MSB positions.
Variable legend: x = input value, n = shift amount, w = bit width (8, 16, 32, or 64), mask = bitmask limiting result to w bits. The & operator is bitwise AND, | is bitwise OR.
Reference Data
| Operation | Symbol | MSB Fill | LSB Fill | Equivalent Math | Use Case |
|---|---|---|---|---|---|
| Logical Left Shift | SHL / << | Discarded | 0 | x ร 2n | Fast multiplication by powers of 2 |
| Logical Right Shift | SHR / >>> | 0 | Discarded | x รท 2n (unsigned) | Unsigned division, bitmask extraction |
| Arithmetic Right Shift | SAR / >> | Sign bit | Discarded | โx รท 2nโ (signed) | Signed division preserving sign |
| Rotate Left | ROL | From LSB | From MSB overflow | Circular permutation | Cryptography, CRC, hash functions |
| Rotate Right | ROR | From LSB underflow | From MSB | Circular permutation | Cryptography, barrel shifters |
| Bit Width: 8 | byte | Range unsigned: 0 - 255, signed: โ128 - 127 | |||
| Bit Width: 16 | word | Range unsigned: 0 - 65535, signed: โ32768 - 32767 | |||
| Bit Width: 32 | dword | Range unsigned: 0 - 4294967295, signed: โ2147483648 - 2147483647 | |||
| Bit Width: 64 | qword | Range unsigned: 0 - 18446744073709551615, signed: โ9223372036854775808 - 9223372036854775807 | |||
| x86 Shift Mask (32-bit) | - | Shift count masked to 5 bits (0 - 31) | |||
| x86 Shift Mask (64-bit) | - | Shift count masked to 6 bits (0 - 63) | |||
| ARM Barrel Shifter | - | Supports all 5 shift types in single instruction cycle | |||
| Two's Complement | - | Negative x stored as 2w โ |x| | |||
| Sign Extension | - | Replicate MSB when widening from n to m bits | |||
| Overflow Detection | - | Left shift overflow when discarded bits โ 0 (or sign bit) | |||