Amazon Interview Question

how to get the most significant bit from a byte?

Interview Answers

Anonymous

Jun 23, 2013

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; }

Anonymous

Apr 18, 2012

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.

Anonymous

Apr 24, 2012

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