Pages

Monday, July 22, 2024

Write a macro to swap adjacent nibbles (word size is 32 bits)

 #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

What is anti- Debugging

  Anti- debugging is how we can stop somebody from debugging our system and getting all the information out of your subsystem.