Binary Bit Shuffler
Shuffle, rotate, reverse, and permute binary bits with 8 algorithms. Visualize bit transformations for numbers, text, and hex values.
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).
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):
Circular left rotation by k positions on an n-bit word:
Butterfly bit-reversal permutation maps bit index i to its bit-reversed position within n bits:
Gray code encoding converts binary to reflected Gray code:
Interleave (perfect/Faro shuffle) splits the bit array into two halves and interleaves them:
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
| Algorithm | Type | Deterministic | Reversible | Complexity | Use Case |
|---|---|---|---|---|---|
| Fisher-Yates | Random permutation | No | No (without seed log) | O(n) | Uniform random bit scrambling |
| Rotate Left | Circular shift | Yes | Yes (rotate right) | O(n) | Barrel shifter, CRC computation |
| Rotate Right | Circular shift | Yes | Yes (rotate left) | O(n) | Hardware register rotation |
| Reverse Bits | Mirror | Yes | Yes (self-inverse) | O(n) | FFT bit-reversal, endian swap |
| Pairwise Swap | Adjacent exchange | Yes | Yes (self-inverse) | O(n) | Nibble manipulation, masking |
| Butterfly (FFT) | Bit-reversal permutation | Yes | Yes (self-inverse) | O(n log n) | FFT preprocessing, network routing |
| Interleave (Faro) | Perfect shuffle | Yes | Yes (inverse Faro) | O(n) | Card shuffling theory, data interleaving |
| Scatter (de Bruijn) | Hash-based spread | Yes | No | O(n) | Hash diffusion, bit-spread operations |
| Custom Permutation | User-defined table | Yes | Depends on table | O(n) | S-box design, cipher construction |
| ROL (x86) | CPU instruction | Yes | Yes | O(1) | Inline assembly equivalent |
| ROR (x86) | CPU instruction | Yes | Yes | O(1) | Inline assembly equivalent |
| XOR Swap | Bitwise exchange | Yes | Yes | O(1) | Register swap without temp variable |
| Gray Code | Encoding transform | Yes | Yes (inverse Gray) | O(n) | Error correction, rotary encoders |
| Hamming Weight | Population count | Yes | No | O(n) | Error detection, set cardinality |
Frequently Asked Questions
Math.random() has only 252 internal states, meaning it cannot produce all permutations for bit widths above approximately 21 bits.(x & 0xAAAA...) >> 1 | (x & 0x5555...) << 1. The tool handles this edge case by leaving the trailing bit unchanged.