Siemens Interview Question Software Engineer in Tests

• 0

Write a function to determine whether the binary representation of a specified 32-bit integer is a palindrome. For example, the 32-bit integer 0xFCA8153F is a palindrome, but 0xFCA88ACF is not. Show how you would test this function.

Comment hidden because of low score. Click to expand.
0
of 0 vote

You could do this bit by bit or nibble by nibble...or even byte by byte (look up table)

Comment hidden because of low score. Click to expand.
0
of 0 vote

This can be done by checking the starting nibbles and end nibbles and the sum of both should be 15(F). This should be true for all the nibbles till you cover all the nibbles.

Comment hidden because of low score. Click to expand.
0

F = 1111- F
E = 1110- 7
D = 1101- B
C = 1100- 3
B = 1011- D
A = 1010- 5
9 = 1001- 9
8 = 1000- 1
7 = 0111- E
6 = 0110- 6
5 = 0101- A
4 = 0100- 2
3 = 0011- D
2 = 0010- 4
1 = 0001- 8
0 = 0000- 0

Comment hidden because of low score. Click to expand.
0
of 0 vote

F = 1111- F
E = 1110- 7
D = 1101- B
C = 1100- 3
B = 1011- D
A = 1010- 5
9 = 1001- 9
8 = 1000- 1
7 = 0111- E
6 = 0110- 6
5 = 0101- A
4 = 0100- 2
3 = 0011- D
2 = 0010- 4
1 = 0001- 8
0 = 0000- 0

Comment hidden because of low score. Click to expand.
0
of 0 vote

F = 1111- F
E = 1110- 7
D = 1101- B
C = 1100- 3
B = 1011- D
A = 1010- 5
9 = 1001- 9
8 = 1000- 1
7 = 0111- E
6 = 0110- 6
5 = 0101- A
4 = 0100- 2
3 = 0011- D
2 = 0010- 4
1 = 0001- 8
0 = 0000- 0

Comment hidden because of low score. Click to expand.
0
of 0 vote

They do not have to be summed up as 15.

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````#define IS_PALINDROME (num) !(num ^ ((num & (1 << 0 ) ) << 31   \
| (num & (1 << 1 ) ) << 29      \
| (num & (1 << 2 ) ) << 27     \
| (num & (1 << 3 ) ) << 25     \
| (num & (1 << 4 ) ) << 23     \
| (num & (1 << 5 ) ) << 21     \
| (num & (1 << 6 ) ) << 19     \
| (num & (1 << 7 ) ) << 17     \
| (num & (1 << 8 ) ) << 15     \
| (num & (1 << 9 ) ) << 13     \
| (num & (1 << 10 ) ) << 11    \
| (num & (1 << 11 ) ) << 09    \
| (num & (1 << 12 ) ) << 07    \
| (num & (1 << 13 ) ) << 05    \
| (num & (1 << 14 ) ) << 03    \
| (num & (1 << 15 ) ) << 01    \
| (num & (1 << 16 ) ) >> 1     \
| (num & (1 << 17 ) ) >> 3     \
| (num & (1 << 18 ) ) >> 5     \
| (num & (1 << 19 ) ) >> 7     \
| (num & (1 << 20 ) ) >> 9     \
| (num & (1 << 21 ) ) >> 11    \
| (num & (1 << 22 ) ) >> 13    \
| (num & (1 << 23 ) ) >> 15    \
| (num & (1 << 24 ) ) >> 17    \
| (num & (1 << 25 ) ) >> 19    \
| (num & (1 << 26 ) ) >> 21    \
| (num & (1 << 27 ) ) >> 23    \
| (num & (1 << 28 ) ) >> 25    \
| (num & (1 << 29 ) ) >> 27    \
| (num & (1 << 30 ) ) >> 29    \
| (num & (1 << 31 ) ) >> 31))``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int reverse(unsigned int num)
{
unsigned int rev=0;
int s = sizeof(num) * 8;
while(num)
{
rev <<= 1;
rev |= num & 1;
num>>=1;
--s;
}
rev <<= s;
return rev;
}
void checkPalindrome(unsigned int number)
{
if(reverse(number)==number)
printf("Palindrome\n");
else
printf("Not Palindrome\n");
}``````

Comment hidden because of low score. Click to expand.
0

way to go

Comment hidden because of low score. Click to expand.
0

reverse function doesn't work for 0001, 0010, 0100 which is less than 8.

Comment hidden because of low score. Click to expand.
0
of 0 vote

void palindrome_32bit_no()
{
unsigned long int x=0xFCA88ACF,A,B;
int i=0,flag=0;

for(i=0;i<16;i++)
{
A=(x & (unsigned long)pow(2.0, 32-i-1) );
B=(x & (unsigned long)pow(2.0, i) );
if((A && B)|| (!A && !B))
flag=1;
else
{
flag=0;
cout<<"\nThe no is not palindrome";
break;
}
}
if(flag==1)
cout<<"\nPalindrome";

}

Comment hidden because of low score. Click to expand.
0

beautiful!!!

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.