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 ?

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

int MSB = 3 & 0x80000000

MSB is now 0?

- Anonymous February 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- vivek April 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
5
of 5 vote

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

- Anonymous October 20, 2011 | Flag Reply
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;
}

- gamespeed April 06, 2012 | Flag Reply
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;

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

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

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

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

- Anonymous August 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Anonymous August 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- akshay October 28, 2011 | Flag Reply
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;
}

- Rohit March 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what abt this

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

}

- Anonymous February 06, 2013 | Flag
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);
}

- Anonymous August 28, 2013 | Flag Reply
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);
}

- swapnilsj August 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int MSB = !!(num & 0x80000000)

- yunpeng September 01, 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