0

What is the most elegant way to check if a binary representation of an integer is a palindrome? Suppose the integer is 32-bit.

Without shifting bits iteratively, can we achieve this? Any code snippet will be highly welcome.

I noticed the post How to check if the binary representation of an integer is a palindrome?, but it is done by bit shifting. Are there any other methods?

Thanks a lot in advance!

Community
  • 1
  • 1
leo
  • 357
  • 2
  • 15

1 Answers1

1

This is really just a special case of reversing bit order since any palindrome will be equal to itself once reversed.

One way or another, you have to reverse the order of the bits, which on some platforms is a single instruction. See the linked question and pick the one you find to be the most elegant.

Community
  • 1
  • 1
Mitch
  • 21,223
  • 6
  • 63
  • 86
  • Thanks for the link. That really helps! – leo Dec 14 '15 at 03:16
  • You may consider accepting the question or upvoting if you feels it addresses your question. Click the checkmark or the arrows next to my answer. – Mitch Dec 14 '15 at 06:01