Re:A Neat Bitwise Trick for Swapping Even and Odd Bits
by lawrencewu on Wednesday March 21, 2018 @12:48PM
(#16639901)
You're right, 8 bits is small enough to just store in a table.
This trick will work for any number of bits though. You might not want to use 2^64 entries in your table.
Re:A Neat Bitwise Trick for Swapping Even and Odd Bits
by joezydeco on Wednesday March 21, 2018 @01:13PM
(#16640214)
The question was an unsigned 8-bit input, not an arbitrary number.
And the "trick" given in the answer still depends on a fixed number of input bits, no matter if it's 8, 32, or 10^100.
The table deference will take 1 or 2 operations instead of the AND/SHIFT/PUSH/AND/SHIFT/POP/OR described in the answer.