Siemens Interview Question for Software Engineer in Tests






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)

- EveryoneLovesMicrosoft November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

bool checkpalindrome(unsigned int num, int bitnum)
{
	int loopcount = bitnum / 2;
	unsigned int temp, temp2;
	for (int i = 0; i < loopcount; i++)
	{
		bitnum -= 1;
		temp = num >> i;
		temp = temp & 1;
		temp2 = num >> bitnum;
		temp2 = temp2 & 1;
		if (temp != temp2)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cout << checkpalindrome(0xFCA8153F,32);
	getchar();
	return 0;

- Anonymous July 18, 2015 | Flag
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.

- Anonymous November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous November 04, 2009 | Flag
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

- Anonymous November 04, 2009 | Flag Reply
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

- Anonymous November 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

They do not have to be summed up as 15.

- Anonymous November 04, 2009 | Flag Reply
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))

- Ashutosh November 05, 2009 | Flag Reply
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");
}

- GK November 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

way to go

- Anonymous November 06, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous February 25, 2011 | Flag
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";

}

- Hemant March 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

beautiful!!!

- Anonymous June 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool checkpalindrome(unsigned int num, int bitnum)
{
	int loopcount = bitnum / 2;
	unsigned int temp, temp2;
	for (int i = 0; i < loopcount; i++)
	{
		bitnum -= 1;
		temp = num >> i;
		temp = temp & 1;
		temp2 = num >> bitnum;
		temp2 = temp2 & 1;
		if (temp != temp2)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cout << checkpalindrome(0xFCA8153F,32);
	getchar();
	return 0;
}

- luck July 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool checkpalindrome(unsigned int num, int bitnum)
{
	int loopcount = bitnum / 2;
	unsigned int temp, temp2;
	for (int i = 0; i < loopcount; i++)
	{
		bitnum -= 1;
		temp = num >> i;
		temp = temp & 1;
		temp2 = num >> bitnum;
		temp2 = temp2 & 1;
		if (temp != temp2)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cout << checkpalindrome(0xFCA8153F,32);
	getchar();
	return 0;

- luck July 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool checkpalindrome(unsigned int num, int bitnum)
{
	int loopcount = bitnum / 2;
	unsigned int temp, temp2;
	for (int i = 0; i < loopcount; i++)
	{
		bitnum -= 1;
		temp = num >> i;
		temp = temp & 1;
		temp2 = num >> bitnum;
		temp2 = temp2 & 1;
		if (temp != temp2)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cout << checkpalindrome(0xFCA8153F,32);
	getchar();
	return 0;
}

- luck July 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool checkpalindrome(unsigned int num, int bitnum)
{
	int loopcount = bitnum / 2;
	unsigned int temp, temp2;
	for (int i = 0; i < loopcount; i++)
	{
		bitnum -= 1;
		temp = num >> i;
		temp = temp & 1;
		temp2 = num >> bitnum;
		temp2 = temp2 & 1;
		if (temp != temp2)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cout << checkpalindrome(0xFCA8153F,32);
	getchar();
	return 0;

- Anonymous July 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool checkpalindrome(unsigned int num, int bitnum)
{
	int loopcount = bitnum / 2;
	unsigned int temp, temp2;
	for (int i = 0; i < loopcount; i++)
	{
		bitnum -= 1;
		temp = num >> i;
		temp = temp & 1;
		temp2 = num >> bitnum;
		temp2 = temp2 & 1;
		if (temp != temp2)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cout << checkpalindrome(0xFCA8153F,32);
	getchar();
	return 0;

- luck July 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool getBit(int num, int bit)
{
	return num & 1 << bit;
}

bool checkPalindrome(int num)
{
	for(int i = 0; i < sizeof(num) * 8 / 2; i++){
		if(getBit(num, i) != getBit(num, sizeof(num) * 8 - 1 - i)) return false;
	}
	return true;
}

- f0vea January 07, 2017 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More