How to check if the binary representation of an integer is a palindrome?
Hopefully correct:
_Bool is_palindrome(unsigned n) { unsigned m = 0; for(unsigned tmp = n; tmp; tmp >>= 1) m = (m << 1) | (tmp & 1); return m == n; }
2.1m questions
2.1m answers
60 comments
57.0k users