. e.g. 0xFE10, should output 0xF(1111 in binary).
This is a Qualcomm interview question. This is my idea so far:
I am calling the 16-bit integer:
int num = /*whatever the number is*/
Have four bit masks:
int zeroTo4 = (num & 0x000F);
int fiveTo5 = (num & 0x00F0) >> 4;
int eightTo12 = (num & 0x0F00) >> 8;
int twelveTo16 = (num & 0xF000) >> 12;
int printbit = zeroTo4;
if( fiveTo5 > printbit )
printbit = fiveTo5;
if( eightTo12 > printbit )
printbit = eightTo12;
if( twelveTo16 > printbit )
printbit = twelveTo16;
printf( "Largest bit of %X is %1X\n", num, printbit );
However, I’m pretty sure there’s a simpler and easier way to do this. Can anyone help me out? Thanks!
Some may prefer: