Given a 64 bit number, I need to extract every other bit from it, and convert it into a number:
binary: 0000 0001 0110 0101
odd bits: 0 0 0 1 1 0 1 1
Any idea of a good algorithmic way to do it? And no, not HW, this is for a real world use :)
Best How To :
I would go with performing Arithmetic Right Shift(till the length of the binary number) two at a time. This
>> used in my logic is for arithmetic shift.
(Note: In C language, right shifts may or may not be arithmetic!)
// binaryLength is the length of the binary_representation_of_the_number
extractLastBit() extracts the LSB of the binary number;
appendLeft() performs shifting the newly extracted bit to the left of the older bit(s).