Adobe Interview Question for Software Engineer / Developers






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

OR with 10101010101..

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

XOR with 10101010101..

OR just sets the bit

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

XOR is right. But there seems to be an ambiguity about definition of odd bits.

Do we count starting from left? right? Do we include the padded zeroes on the left?

- LOLer July 31, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

oops..yeah..shouldnt post at 1:30am..:D

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

XOR is correct. just wondering if most bit problems end up using XOR ;)

- Addy September 12, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The correct answer is
OR with 10101010101..
I don't think XOR works. Just try it

- Avinash September 14, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

OR does not work, avinash. Just try it.

- Satyanash September 14, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes xor with 0x55555555

- Psycho October 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ummmm, flip ALL odd bits of a number, that will just set it to 0.

AND with 0 and call it.... wtf kind of question is this?

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

nvm misunderstood the question

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

> count no. of bits

int t=n,c=0;

while(t)
{
c++;
t&=t-1;
}

int k=0;

while(k<c)
{
if(k&1)n^=0<<k;

k++;

}

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

sorry.....plz ignore the above

> find posn of highest set bit .

int t=n,c=0;
while(t)
{
c++;
t>>=1;
}

int k=0;
while(k<c-1)
{

if(k&1)n^=1<<k;

k++;

}

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

Above solution assumes the length of bits used.

int ToggleOddBits(int input){
int x=2;
while(x != 0){
input ^= x;
x= x<<2;
}
return input;
}

Please revert back if you dont agree with the above function.

- Ankush Bindlish November 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The Solution seems to be working. XORing with 2 will lead to all the odd positions from left. If we do XOR with 1, then it will lead to flipping all the odd positions from right.

- Anshul March 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

That doesn't work, because you are trying to do xor till x becomes 0, not till the end of the given number

- Ashok January 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int flipAllOddBitsOfNumber( final int num){
// Convert the no into a binary String
int N = num;
String binary="";
while(N!=0){
binary = N%2 + binary ;
N/=2;
}
// Flip bits at odd position in binary String
char [] car = binary.toCharArray();
for(int i =1 ; i<car.length ;i+=2)
if (car[i]=='0' )
car[i] = '1';
else
car[i] = '0';

// Convert from binary to decimal
int result =0;
for(int i = car.length - 1 ; i>=0 ; --i){
int powerTwo=1;

for(int j = 1 ; j < car.length -i ;++j )
powerTwo*= 2;
result+= powerTwo* (car[i] - '0');
}

return result ;
}

- Anon January 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The following program should work. Havent tested it though.

int main ()
{
	int num;
	cin >> num;
	
	char num_char[33];
	int i = 0;

	itoa(num, num_char, 10);
	while (num_char[i] != '\0')
	{
		if ( (i%2) != 0)
		{
			if (num_char[i] == '0')
				num_char[i] = '1';
			else
				num_char[1] = '0';
		}

		i++;
	}

	num = atoi(num_char);
	
	cout << num;
	return 0;
}

- AK January 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Flip odd bits of a number
//Ex : 10001001->11011100
int FlipOddBits(int num)
{
int size = sizeof(num) * 8;
int i = 0;
int tmp=1;
for(i=0;i<size;i=i+2)
{
if(num & tmp)
{
num = num & (~tmp);
}
else
{
num = num | tmp;
}
tmp = tmp<<2;
}
return num;
}

- Srini Edara May 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

size_t = sizeof(int)*8;
int tmpVal

- Umesh May 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int flipOddBits(int num)
{
size_t = sizeof(int)*8;
int tmpVal = 1;
while(tmpVal < power(2,size))
{
num = num ^ tmp;
tmpVal = tmpVal <<2;
}
return num;
}

- Umesh May 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

nt FlipOddBits(int num)
{
int size = sizeof(num) * 8;
int i = 0;
int tmp=1;
for(i=0;i<size;i=i+2)
{
if(num & tmp)
{
num = num & (~tmp);
}
else
{
num = num | tmp;
}
tmp = tmp<<2;
}
return num;
}

- Anonymous October 16, 2013 | 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