@Piyush, yes true. and thanks for the clarification.

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(getIthBit(num, j)) j--;*
     while (i < j) {
           int ithbit = getIthBit(num, i);
           int jthbit = getIthBit(num, j);
           if ( ithbit ^ jthbit) return false;
           i++;j--;
     }
     return true;
}


On Tue, May 24, 2011 at 1:23 PM, Piyush Sinha <ecstasy.piy...@gmail.com>wrote:

> @immanuel....the question doesn't require you to check with the whole
> 32 bit number...
>
> For example, taking 10's binary representation as 1010...according to
> question it wil be a palindrome...but according to ur algo it will
> return false...
>
> On 5/24/11, immanuel kingston <kingston.imman...@gmail.com> wrote:
> > #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
> > <ecstasy.piy...@gmail.com>wrote:
> >
> >> Constraint is no extra space and the complexity should be as efficient
> >> as possible.
> >>
> >> On 5/24/11, 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.
> >> >
> >> >
> >>
> >>
> >> --
> >> *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.
> >>
> >>
> >
> > --
> > 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.
> >
> >
>
>
> --
> *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.
>
>

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