User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Prefix: 0x (hex), 0b (bin), 0o (oct), or plain decimal. Negative sign allowed in signed mode.
Quick Presets
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

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.

bit shift bitwise calculator binary shift logical shift arithmetic shift rotate bits bitwise operations

Formulas

Logical left shift multiplies the operand by a power of two, discarding bits that exceed the register width.

result = (x << n) & mask

where mask = 2w โˆ’ 1 and w is the bit width.

Logical right shift fills vacated high bits with zero.

result = (x & mask) >>> n

Arithmetic right shift preserves the sign bit via replication.

result = x >> n , with MSB filled by x[w โˆ’ 1]

Rotate left wraps overflow bits from MSB to LSB positions.

ROL(x, n) = (x << n) | (x >>> (w โˆ’ n))

Rotate right wraps underflow bits from LSB to MSB positions.

ROR(x, n) = (x >>> n) | (x << (w โˆ’ n))

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

OperationSymbolMSB FillLSB FillEquivalent MathUse Case
Logical Left ShiftSHL / <<Discarded0x ร— 2nFast multiplication by powers of 2
Logical Right ShiftSHR / >>>0Discardedx รท 2n (unsigned)Unsigned division, bitmask extraction
Arithmetic Right ShiftSAR / >>Sign bitDiscardedโŒŠx รท 2nโŒ‹ (signed)Signed division preserving sign
Rotate LeftROLFrom LSBFrom MSB overflowCircular permutationCryptography, CRC, hash functions
Rotate RightRORFrom LSB underflowFrom MSBCircular permutationCryptography, barrel shifters
Bit Width: 8byteRange unsigned: 0 - 255, signed: โˆ’128 - 127
Bit Width: 16wordRange unsigned: 0 - 65535, signed: โˆ’32768 - 32767
Bit Width: 32dwordRange unsigned: 0 - 4294967295, signed: โˆ’2147483648 - 2147483647
Bit Width: 64qwordRange 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)

Frequently Asked Questions

Logical right shift (>>>) fills vacated high-order bits with 0, treating the operand as unsigned. Arithmetic right shift (>>) replicates the sign bit (MSB) into vacated positions, preserving the two's complement sign. For unsigned values they produce identical results. For negative signed values, arithmetic shift yields a negative result (floor division by 2n), while logical shift produces a large positive number.
Behavior varies by architecture. On x86, the shift count is masked: for 32-bit values, count & 31; for 64-bit, count & 63. This calculator applies the same masking by default. A shift of 32 on a 32-bit value is equivalent to a shift of 0 under x86 masking. ARM behaves differently: shifting by the full width produces 0 for logical shifts. Always check your target ISA.
In signed mode with bit width w, values from 0 to 2wโˆ’1 โˆ’ 1 are positive. Values from 2wโˆ’1 to 2w โˆ’ 1 represent negative numbers. The calculator accepts negative decimal input and converts it to two's complement binary automatically. For example, โˆ’1 in 8-bit is 0xFF (255 unsigned).
Rotate operations preserve all bits - no information is lost. They are critical in cryptographic algorithms (AES uses byte rotation, SHA-256 uses 32-bit rotates), CRC computation, and hash functions. Unlike linear shifts, rotates are reversible: ROR(ROL(x, n), n) = x. Use them when you need bit permutation without data loss.
Yes. If any of the n most-significant bits being shifted out are non-zero, data is lost. For signed values, overflow also occurs when the sign bit changes. This calculator masks the result to the selected bit width, which silently discards overflow bits. The binary visualization highlights discarded bits so you can see when overflow occurs. In production code, check the discarded bits: overflow = x >>> (w โˆ’ n) โ‰  0.
Use standard programming prefixes: 0x for hexadecimal (e.g., 0xFF), 0b for binary (e.g., 0b10110011), and 0o for octal (e.g., 0o377). Unprefixed numbers are parsed as decimal. The calculator validates that the value fits within the selected bit width and sign mode before computing.