## NVIDIA Interview Question for Software Engineer / Developers

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

Can we not find MSB of 32 bit integer using
int MSB = num & ox80000000 ?

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

int MSB = 3 & 0x80000000

MSB is now 0?

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

Are you suffering with a misconception that MSB is always one ? MSB can be zero too .32 bit version of 3 has its MSB 0.
Correct ans : int MSB = (3 & 0x80000000) >> 32

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

floor(log2(number)) this answer is posted elsewhere on this site..

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

``````bool msb(unsigned int n)
{
if (n > ~n)
return true;
else
return false;
}``````

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

for(int i=sizeof(int);i>=0;i--)
{
if(num & (1<< i))
break;
}
return i;

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

for(int i=sizeof(int)*8,.......same)

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

if (num = (num << 1) >> 1) msb 1 else 0

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

if (num == (num << 1) >> 1) msb 1 else 0

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

``if((num&(0x80))!=0) then msb=1; else msb=0;``

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

``````bool msb(unsigned int N)
{
N= N>>((sizeof(int)*8)-1);
if(N%2) return true;
return false;
}``````

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

what abt this

bool msb_check(int N)
{
if(N > 0)
return false;
else
return true;
}

}

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

I think the question is not worded correctly. I think we have to find the highest set bit. If so, the fast solution is to set all bits to the right of the hibit and then subtract as below.

``````int hibit(unsigned int n) {
n |= (n >>  1);
n |= (n >>  2);
n |= (n >>  4);
n |= (n >>  8);
n |= (n >> 16);
return n - (n >> 1);
}``````

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

``````int findMSB(int a){
return (a & 0x80000000) ? 31 : (findMSB((a << 1) | 1) - 1);
}``````

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

int MSB = !!(num & 0x80000000)

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.