[math-fun] reversing the order of bits in a word
29 Mar
2014
29 Mar
'14
12:52 a.m.
Knuth gave the following absolutely incredible algorithm, here as C which I tested: //Don Knuth incredible algorithm for reversing a 64-bit word x: uint64 y; x = ((x>>1) & U64(0x5555555555555555)) | ((x & U64(0x5555555555555555)) << 1); y = (x ^ (x>>4)) & U64(0x0300C0303030C303); x ^= y ^ (y<<4); y = (x ^ (x>>8)) & U64(0x00C0300C03F0003F); x ^= y ^ (y<<8); y = (x ^ (x>>20)) & U64(0x00000FFC00003FFF); x ^= y ^ (y<<20); x = (x>>34) | (x<<30); return(x); Good luck figuring it out. And what are the 8, 16, and 32-bit versions of it (if any)?
4255
Age (days ago)
4255
Last active (days ago)
0 comments
1 participants
participants (1)
-
Warren D Smith