## Imagination Technologies Interview Question for Graphics Programmers

• 0

Country: India
Interview Type: Phone Interview

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

Simply swap the first occurrence of the 01 pair or 10 pair, and you will reach a step up or step down integer. Code should look something like:

``````int NextInt(int n)
{
int bit = n & 0x01;
{
if (n & mask != bit)
{
break;
}
}

if (bit == 1)
{
n &= (mask >> 1) ^ 0xFFFFFFFF;
}
else
{
}
}``````

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

swap the first occurence of 01 with 10 for the next higher
swap the first occurence of 10 with 01 for the next lower
while taking into account the max int and lowest boundary conditions.

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

@yemre_ankara ....just swapping first occurence of 01 with 10 won't give you the immediate next heighest number for ex consider 12 ( 1100 )...with what you say the next heighest number will be (10100) i.e 20 but the next heighest integer is 17 i.e (10001)

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

for(int i = n-1 ; i >= -n ; i--){
if( length == CountNumberOfOnes(i)){
cout << "Lower value with same number of 0's :" << i << endl;
break;
}
}

for(int i = n+1 ; i <= (n*10) ; i++){
if( length == CountNumberOfOnes(i)){
cout << "Higher value with same number of 0's :" << i << endl;
break;
}
}

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

In your above code, if we take n=0 then what will happen??

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.

### 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.