For a FFT function I need to permutate or shuffle the elements within an array in a bit-reversed way. That\'s a common task with FFTs because most power of two sized FFT fun
A quick way to do this is to swap every adjacent single bit, then 2-bit fields, etc. The fast way to do this is:
x = (x & 0x55) << 1 | (x & 0xAA) >> 1; //swaps bits
x = (x & 0x33) << 2 | (x & 0xCC) >> 2; //swapss 2-bit fields
x = (x & 0x0F) << 4 | (x & 0xF0) >> 4;
While hard to read, if this is something that needs to be optimized you may want to do it this way.