If you are ignoring the leading zeros, no even number can be a palindrome.
hence we can ignore them and only will check for the odd ones.


> #include <stdio.h>
>
> int palindrome(int x)
> {
>         int y = 0;
>         int temp = x;
>
>         if ( !(x % 2) )
>                 return 0;
>
>         while ( temp ) {
>                 y <<= 1;
>                 y |= temp & 1;
>                 temp >>= 1;
>         }
>
>         return ( x == y );
> }
>
> int main()
> {
>         int x;
>
>         scanf ("%d", &x);
>
>         printf ("%s\n", palindrome(x)?"Palindrome":"Not a Palindrome");
>
>         return 0;
> }
>


On Tue, May 24, 2011 at 2:48 PM, Dave <dave_and_da...@juno.com> wrote:

> Ignoring leading zeros in the number:
>
> bool isPalindrome(int N)
> {
>    int i = 0, j = N;
>    while(n)
>    {
>        i = (i << 1) | (j & 1);
>        j >= 1;
>    }
>    return(i == N);
> }
>
> Dave
>
> On May 23, 2:11 pm, Piyush Sinha <ecstasy.piy...@gmail.com> wrote:
> > Find whether the binary representation of a number is palindrome or
> > not. The input begins with integer N.
> > --
> > *Piyush Sinha*
> > *IIIT, Allahabad*
> > *+91-8792136657*
> > *+91-7483122727*
> > *https://www.facebook.com/profile.php?id=100000655377926*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@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.
>
>


-- 
-Aakash Johari
(IIIT Allahabad)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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.

Reply via email to