Write a code for determining the given integer is palindrome in binaries.
Interview Answers
Anonymous
Oct 5, 2010
Reverse the bit of the given integer. Then compare it with the original.
Anonymous
Oct 19, 2010
int palin(int x){
int i, j, flag=0;
i=15; j = 17; /* assuming 32 bit integer */
while( x&(1<
Anonymous
Feb 15, 2011
Add to the candidate.
Reverse all the bits by exchanging adjacent bits, adjacent two bits, adjacent four bits, etc...O(log n).. n is the number of bits in the number
Then XOR with original, to see if result is 0, otherwise not palindrome
Anonymous
Feb 21, 2011
import os,sys
def is_palindrome(x):
t=x;
cnt=0;
while t>0:
print t
t>>=1;
cnt+=1;
print cnt;
for i in range(cnt/2):
if ((x & (1 0) != ((x & (1 0):
return False
return True
print is_palindrome(5)