Anonymous
BAN USER
Comments (5)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
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.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Answer is undefined behavior. This is because the '+' between i++ and ++i is NOT a sequence point. A sequence point is a point in code where side effects like ++ of all previous computations is completed. Example of sequence points are ; (end of statement), ? in ?: operator, logical operators like &&, ||, etc.
- Anonymous August 28, 2013Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
@Nvidia reject: Were you answering questions or taking them down?? So many questions and being able to recall them all! Thanks!
- Anonymous August 29, 2013