#define SWAP_NIBBLE(num) (((num & 0xF0F0F0F0) >>4) | ((num & 0x0F0F0F0F) << 4)))
Explanation
if num = 0x12345678 the output should be 0x21436587
Extract the alternate nibbles and shit by 4
((num & 0xF0F0F0F0) >>4) = 0x01030507
((num & 0x0F0F0F0F) << 4) = 0x20406080
ANDing both we get
0x21436587
No comments:
Post a Comment