Palindrome Bit Representation

Check if binary representation of an int is a palindrome or not.
Answer:


Approach I:
Reverse the first word of the number and compare with the second word.

Apporach II:
Use a lookup table which contains the reverse of numbers from [0,0xFF]
#define IS_PALINDROME(num) ( (num & 0xFF) == lookup[num>>24] ) && (num>>8 & 0xFF) == lookup[num>>16] )

No comments: