A Neat Bitwise Trick For Swapping Even and Odd Bits · Daily Coding Problem
Here's a problem that was asked by Cisco.
Given an unsigned 8-bit integer, swap its even and odd bits. The 1st and 2nd bit should be swapped, the 3rd and 4th bit should be swapped, and so on.
For example, 10101010
should be 01010101
.
Bonus: Can you do this in one line?
Read full article from A Neat Bitwise Trick For Swapping Even and Odd Bits · Daily Coding Problem
No comments:
Post a Comment