#define MAX_BITS_FOR_INT=32;

int getIthBit(int n, int i) {
     return (n & 1<<i) >> i;
}
bool isPalindrome(int num) {
    int i=0;
    int j= MAX_BITS_FOR_INT - 1;
    while (i < j) {
          int ithbit = getIthBit(num, i);
          int jthbit = getIthBit(num, j);
          if ( ithbit ^ jthbit) return false;
          i++;j--;
    }
    return true;
}

Thanks,
Immanuel

On Tue, May 24, 2011 at 12:42 AM, Piyush Sinha <[email protected]>wrote:

> Constraint is no extra space and the complexity should be as efficient
> as possible.
>
> On 5/24/11, 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.
> >
> >
>
>
> --
> *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.
>
>

-- 
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.

Reply via email to