Write a code for determining the given integer is palindrome in binaries.
Respostas da entrevista
Sigiloso
5 de out. de 2010
Reverse the bit of the given integer. Then compare it with the original.
Sigiloso
19 de out. de 2010
int palin(int x){
int i, j, flag=0;
i=15; j = 17; /* assuming 32 bit integer */
while( x&(1<
Sigiloso
15 de fev. de 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
Sigiloso
21 de fev. de 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)