User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Enter a decimal integer (0–2⁢⁴)
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

Bit-level permutations underpin cryptographic S-boxes, hash function diffusion layers, and hardware register scrambling. A single misplaced bit in a permutation table corrupts the entire output irreversibly. This tool applies 8 distinct shuffle algorithms to binary representations of integers, hexadecimal values, or UTF-8 text. It operates on bit widths from 8 to 64 bits and renders each transformation step visually so you can trace exactly which bit moved where. The Fisher-Yates shuffle produces uniformly random permutations with O(n) complexity. Circular rotations follow the barrel-shifter model used in ARM and x86 ROL/ROR instructions. The butterfly shuffle mirrors the bit-reversal permutation stage of the Cooley-Tukey FFT algorithm.

Limitations apply. The tool uses Math.random() for stochastic shuffles, which is not cryptographically secure. For CSPRNG-grade permutations, pipe the permutation table into a hardware RNG. Bit widths above 32 use JavaScript BigInt, which lacks constant-time guarantees. All operations assume unsigned integers with big-endian bit ordering (MSB at index 0).

binary bit manipulation bit shuffle bitwise operations binary converter bit permutation fisher-yates circular shift

Formulas

The Fisher-Yates shuffle generates a uniformly random permutation by iterating from the last element to the first, swapping each element with a randomly chosen predecessor (inclusive):

for i = n βˆ’ 1 down to 1: swap bits[i] with bits[rand(0, i)]

Circular left rotation by k positions on an n-bit word:

result = (x << k) | (x >>> (n βˆ’ k))

Butterfly bit-reversal permutation maps bit index i to its bit-reversed position within n bits:

j = reverse(i, log2n)

Gray code encoding converts binary to reflected Gray code:

G = B βŠ• (B >> 1)

Interleave (perfect/Faro shuffle) splits the bit array into two halves and interleaves them:

out[2i] = top[i], out[2i + 1] = bottom[i]

Where n = bit width, x = input value, k = shift amount, B = binary value, G = Gray-coded value, i = bit index, βŠ• = XOR operation, << = left shift, >>> = unsigned right shift.

Reference Data

AlgorithmTypeDeterministicReversibleComplexityUse Case
Fisher-YatesRandom permutationNoNo (without seed log)O(n)Uniform random bit scrambling
Rotate LeftCircular shiftYesYes (rotate right)O(n)Barrel shifter, CRC computation
Rotate RightCircular shiftYesYes (rotate left)O(n)Hardware register rotation
Reverse BitsMirrorYesYes (self-inverse)O(n)FFT bit-reversal, endian swap
Pairwise SwapAdjacent exchangeYesYes (self-inverse)O(n)Nibble manipulation, masking
Butterfly (FFT)Bit-reversal permutationYesYes (self-inverse)O(n log n)FFT preprocessing, network routing
Interleave (Faro)Perfect shuffleYesYes (inverse Faro)O(n)Card shuffling theory, data interleaving
Scatter (de Bruijn)Hash-based spreadYesNoO(n)Hash diffusion, bit-spread operations
Custom PermutationUser-defined tableYesDepends on tableO(n)S-box design, cipher construction
ROL (x86)CPU instructionYesYesO(1)Inline assembly equivalent
ROR (x86)CPU instructionYesYesO(1)Inline assembly equivalent
XOR SwapBitwise exchangeYesYesO(1)Register swap without temp variable
Gray CodeEncoding transformYesYes (inverse Gray)O(n)Error correction, rotary encoders
Hamming WeightPopulation countYesNoO(n)Error detection, set cardinality

Frequently Asked Questions

Circular rotation (ROL/ROR) preserves all bit relationships by shifting every bit the same number of positions. It is deterministic and reversible. Fisher-Yates shuffle randomly permutes bit positions with uniform probability, destroying the original positional structure. Rotation has O(1) complexity on hardware; Fisher-Yates runs in O(n) time. Use rotation for cryptographic primitives (e.g., SHA-256 uses ROTR). Use Fisher-Yates only when you need a truly random arrangement.
The Cooley-Tukey FFT requires input data reordered by bit-reversed indices before the butterfly computation stages. For an 8-bit index, position 3 (binary 011) maps to position 6 (binary 110). This tool applies that same index-reversal to the bit values themselves. The permutation is an involution: applying it twice restores the original. This property makes it useful for self-inverting ciphers.
An n-bit value has n! possible bit permutations. For 8 bits: 40,320 permutations. For 16 bits: 20,922,789,888,000. For 32 bits: approximately 2.63 Γ— 1035. The Fisher-Yates algorithm samples uniformly from this space, but JavaScript's Math.random() has only 252 internal states, meaning it cannot produce all permutations for bit widths above approximately 21 bits.
Only if you record the exact sequence of random indices generated during the forward shuffle. The tool logs each swap in the history panel. To reverse: replay the swap sequence in reverse order. Without the swap log, recovery is computationally equivalent to brute-forcing n! permutations. For 32 bits, this is infeasible.
Gray code is a binary encoding where consecutive values differ by exactly 1 bit. Standard binary counting can flip multiple bits simultaneously (e.g., 0111 β†’ 1000 flips 4 bits). Gray code eliminates this, reducing switching noise in digital circuits and rotary encoders. The formula is G = B βŠ• (B >> 1). The inverse requires iterative XOR from MSB to LSB.
Pairwise swap exchanges adjacent pairs: bit 0 with 1, bit 2 with 3, etc. For odd bit widths, the last bit has no partner and remains in place. This is consistent with the standard bitmask implementation: (x & 0xAAAA...) >> 1 | (x & 0x5555...) << 1. The tool handles this edge case by leaving the trailing bit unchanged.