Interview Question

Software/Test Engineer Interview Seattle, WA

how to get the most significant bit from a byte?

Tags:
algorithm
Answer

Interview Answer

3 Answers

0

I couldnt understand what he ment by byte. I thought eight bits in binary format. But what he was asking about converting a decimal number into binary and getting the most significant bit out of it.

Interview Candidate on Apr 18, 2012
0

right shift the number by 7 positions and you get the most significant bit
printf("%d",n>>7);

rkt on Apr 23, 2012
0

If he was asking about converting a decimal integer number into binary and getting the most significant bit out of it, then the answer is just: divide by 2, again and again until you get the last '1';

Or using programming code:
while(x)
{
  x >>= 1;
  ++n;
}

Peter on Jun 23, 2013

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up