Saturday, January 7, 2012

Bit Palindrome

Write a function to check if the bit-wise representation of an integer is a palindrome.
eg. 5, 9, etc. are palindromes.

1 comment:

  1. #include < stdio.h >
    #include < conio.h >
    int main()
    {
    int num,ntmp,tmp;
    scanf("%d",&num);

    tmp=0;
    ntmp=num;
    while(ntmp)
    {
    tmp=tmp|(ntmp&1);
    ntmp=ntmp >> 1;
    tmp=tmp << 1;
    printf("%d %d\n",ntmp,tmp);
    }
    tmp=tmp >> 1;
    if(tmp==num)
    printf("palindrome\n");
    else
    printf("not a palindrome\n");
    getch();
    return 0;
    }

    ReplyDelete