#include #include int checkbits(short n, int bits) { int is_palindrome = 1; int i; for(i = 0; is_palindrome && i < bits / 2; i++) { if(((n & (1 << i)) > 0) != ((n & (1 << (bits - 1 - i))) > 0)) { is_palindrome = 0; } } return is_palindrome; } int main(void) { short int i = SHRT_MAX; int bits = 1; /* sign bit */ int is_palindrome = 1; short n; while(i > 0) { ++bits; i >>= 1; } for(n = SHRT_MIN; n < SHRT_MAX; n++) { if(checkbits(n, bits)) { printf("%hd is a binary palindrome.\n", n); } } if(checkbits(n, bits)) { printf("%hd is a binary palindrome.\n", n); } return 0; }