## Adobe Interview Question for Software Engineer / Developers

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

The i guess is that first convert the given floating number to binary. The conversion has a procedure which is done by multiplying the fractional part by 2. I dont remember exactly but can be found on net. Then, simply count the set bits.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Simplest to me seems like breaking a float number into two parts. One part being its integer part, represented as an integer number and second part being the decimal part represented as an integer number as well. One you have that then just count the number of bits set in each integer. For example:

``````float x = 16.15f;
int int_x = (int) x;
int dec_x = (int) ((x - int_x) * 10000);``````

int_x = 16 and dec_x = 1499

Comment hidden because of low score. Click to expand.
0
of 0 vote

There's basically something like an assembly instruction that can move the bits from a floating-point register to an integer register in the CPU bit-for-bit. In Java, there's a function called Float.floatToRawIntBits that I think generally just accesses that assembly instruction. You would then be free to use bit operations on that int.

``````public int countFloatBits (float value)
{
int intVal = Float.floatToRawIntBits(intVal);
int numBitsSet = 0;
while (intVal != 0)
{
intVal = intVal << 1;
numBitsSet++;
}
return numBitsSet;
}``````

At least I think that this is the kind of thing this question is asking for...

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int numFloatBits( const float & x )
{
unsigned int intVal = *( reinterpret_cast< unsigned int * >( &x ) );
int bitSetCount = 0;
for( int i = 0; i < ( sizeof( intVal)  * 8 ) - 1 ; i++ )
{
if( ( ( intVal >> i  ) & 0x1 ) == 0x1 )
{
bitsSetCount++;
}
}
return bitsSetCount;
}``````

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.

### 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.