Monday, November 15, 2010

Bit Reversal

Let's consider reversing a byte in a speedy way using some parallelism.
Byte b;
b = b & FO >> 4  | b & OF << 4; // This swaps the nibbles.
b = b & CC >> 2 | b & 33 << 2; // swap bit pairs in each nibble.
b = b & AA >> 1 | b & 55 << 1; // swap even / odd bits
Done!

No comments: