Okay. That wouldn't change the order. But allowing any number of
leading zeros in the number:
bool isPalindrome(unsigned int N)
{
unsigned int i = 0, j = N;
while(n)
{
i = (i << 1) | (j & 1);
j >= 1;
}
while(i < N)
i <<= 1;
return(i == N);
}
Dave
On May 24, 5:40 pm, Aakash Johari <[email protected]> wrote:
> 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 <[email protected]> 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 <[email protected]> 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 [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> -Aakash Johari
> (IIIT Allahabad)- Hide quoted text -
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.