Hi, Here is the simple solution
unsigned int r = v; // r will be reversed bits of v; first get LSB of v int s = sizeof(v) * CHAR_BIT - 1; // extra shift needed at end for (v >>= 1; v; v >>= 1) { r <<= 1; r |= v & 1; s--; } r <<= s; // shift when v's highest bits are zero if (v == r) printf("palindrome\n"); else printf("not a palindrome\n"); source and more optimized versions http://www-graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious - Azhar. On Wed, Dec 22, 2010 at 2:09 PM, pacific pacific <pacific4...@gmail.com>wrote: > > > On Wed, Dec 22, 2010 at 12:11 PM, mo...@ismu <mohan...@gmail.com> wrote: > >> >> >> if x is a 32 bit number >> if((x&0x0000FFFF)==((x>>16)&0x0000FFFF))) >> x's bit pattern is a polyndrome >> >> @snehal :Do you want to consider binary representation of 5 as 101 or > 0000..0101 ? > -- > >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.