User Rating 0.0
Total Usage 0 times
Presets:
Is this tool helpful?

Your feedback helps us improve.

About

Circular bit rotation differs from arithmetic shifts in one critical way: bits shifted out on one end re-enter on the opposite end rather than being discarded. Confusing a logical shift with a rotation causes silent data corruption in cryptographic algorithms (AES, SHA-256), CRC checksums, and hardware register manipulation. The left rotation (ROL) of a value x by n positions within a w-bit register is defined as (x << n) | (x >>> (w n)), masked to w bits. This tool computes both ROL and ROR for 8, 16, 32, and 64-bit widths with correct overflow handling. The 64-bit path uses BigInt arithmetic to avoid JavaScript's 32-bit signed integer truncation.

This tool accepts decimal, hexadecimal, and binary input. It validates range against the selected bit width and displays the result across all three bases. The animated bit grid visualizes exactly which bits wrap around during rotation. Note: rotation amount is taken modulo the bit width, so rotating an 8-bit value by 10 positions is equivalent to rotating by 2.

bit rotation binary rotator circular shift bitwise operations bit manipulation ROL ROR

Formulas

The circular left rotation (ROL) of an unsigned integer x by n bit positions within a w-bit register:

ROL(x, n) = (x << neff) | (x >>> (w neff)) & mask

The circular right rotation (ROR):

ROR(x, n) = (x >>> neff) | (x << (w neff)) & mask

Where the effective rotation count and bit mask are:

neff = n mod w
mask = 2w 1

Where x = unsigned integer input, n = rotation amount (positions), w = bit width (8, 16, 32, or 64), neff = effective rotation after modulo reduction, mask = bitmask to constrain result to w bits. The operators << and >>> denote logical (unsigned) left and right shift respectively. The | is bitwise OR that merges the shifted halves. For w = 64, JavaScript BigInt is used because the native >>> operator truncates to 32 bits.

Reference Data

OperationMnemonicDefinitionCommon Use
Rotate LeftROLBits shifted left; MSB wraps to LSBSHA-256, CRC, AES MixColumns
Rotate RightRORBits shifted right; LSB wraps to MSBARM instruction set, hash functions
Logical Shift LeftSHL / LSLBits shifted left; 0 fills LSBMultiplication by 2
Logical Shift RightSHR / LSRBits shifted right; 0 fills MSBUnsigned division by 2
Arithmetic Shift RightSAR / ASRBits shifted right; sign bit preservedSigned division by 2
Rotate Through Carry LeftRCLROL including carry flag as extra bitx86 multi-word arithmetic
Rotate Through Carry RightRCRROR including carry flag as extra bitx86 multi-word arithmetic
Bit Width: 8 - Range: 0 - 255 (0xFF)Byte-level registers, I2C
Bit Width: 16 - Range: 0 - 65535 (0xFFFF)UTF-16 code units, TCP ports
Bit Width: 32 - Range: 0 - 4294967295 (0xFFFFFFFF)IPv4, SHA-256 words, IEEE 754 float
Bit Width: 64 - Range: 0 - 18446744073709551615SHA-512 words, memory addresses
ROL identity - ROL(x, 0) = xNo-op rotation
Full rotation - ROL(x, w) = xRotation by bit width is identity
Inverse - ROR(x, n) = ROL(x, w n)Reversibility property
SHA-256 Σ0 - ROR(x,2) ROR(x,13) ROR(x,22)SHA-256 compression function
SHA-256 Σ1 - ROR(x,6) ROR(x,11) ROR(x,25)SHA-256 compression function

Frequently Asked Questions

A logical shift (SHL/SHR) discards bits that overflow the register width and fills the vacated positions with zeros. A circular rotation (ROL/ROR) preserves all bits by wrapping overflowed bits to the opposite end. For an 8-bit value 0b11000001 shifted left by 1, logical shift yields 0b10000010 (MSB lost, LSB = 0), while ROL yields 0b10000011 (MSB wraps to LSB). This distinction is critical in cryptographic algorithms where no information loss is permitted.
Rotation is cyclic with period equal to the bit width. ROL(x, w) moves every bit exactly w positions, returning each to its original location. The tool reduces the rotation amount modulo the bit width (n_eff = n mod w), so ROL(x, 8) on an 8-bit value is equivalent to ROL(x, 0). This is defined by the algebraic group structure of cyclic permutations on a w-element set.
JavaScript's bitwise operators (<<, >>>, |, &) internally convert operands to 32-bit signed integers. Values above 2^31 - 1 (2147483647) are truncated or produce incorrect sign-extended results. BigInt provides arbitrary-precision integer arithmetic, correctly handling the full 0 to 2^64 - 1 range. The performance cost is negligible for single-value operations.
SHA-256 uses 32-bit right rotations in its compression function. The Σ₀ function computes ROR(x,2) ⊕ ROR(x,13) ⊕ ROR(x,22), and Σ₁ computes ROR(x,6) ⊕ ROR(x,11) ⊕ ROR(x,25). These rotations provide diffusion: a 1-bit change in input propagates to many output bits. Using shifts instead of rotations would break the hash function's collision resistance.
The tool validates input against the maximum unsigned value for the selected width: 255 for 8-bit, 65535 for 16-bit, 4294967295 for 32-bit, and 18446744073709551615 for 64-bit. Values exceeding the range are rejected with an error message. If you need to rotate a larger value, select a wider bit width first.
The tool accepts rotation amounts from 0 to the bit width. A negative rotation is mathematically equivalent to rotating in the opposite direction: ROL(x, -n) = ROR(x, n). Use the direction toggle (Left/Right) instead of negative values to achieve the desired effect.