Binary Bit Rotator
Perform circular bit rotation (left/right) on binary, hex, or decimal values with visual bit grid and step-through animation.
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.
Formulas
The circular left rotation (ROL) of an unsigned integer x by n bit positions within a w-bit register:
The circular right rotation (ROR):
Where the effective rotation count and bit mask are:
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
| Operation | Mnemonic | Definition | Common Use |
|---|---|---|---|
| Rotate Left | ROL | Bits shifted left; MSB wraps to LSB | SHA-256, CRC, AES MixColumns |
| Rotate Right | ROR | Bits shifted right; LSB wraps to MSB | ARM instruction set, hash functions |
| Logical Shift Left | SHL / LSL | Bits shifted left; 0 fills LSB | Multiplication by 2 |
| Logical Shift Right | SHR / LSR | Bits shifted right; 0 fills MSB | Unsigned division by 2 |
| Arithmetic Shift Right | SAR / ASR | Bits shifted right; sign bit preserved | Signed division by 2 |
| Rotate Through Carry Left | RCL | ROL including carry flag as extra bit | x86 multi-word arithmetic |
| Rotate Through Carry Right | RCR | ROR including carry flag as extra bit | x86 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 - 18446744073709551615 | SHA-512 words, memory addresses |
| ROL identity | - | ROL(x, 0) = x | No-op rotation |
| Full rotation | - | ROL(x, w) = x | Rotation 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 |