Floating point representation (using bitwise operators)
<p>This is a solution to a problem to print the representation of a floating point (i.e : x = (−1)^sign · (1.m 22 m 21 m 20 . . . m 0 ) · 2^(e −bias) ) and I haven't understood some things in it :
1) The use of the union, why ?
2) MANTISSA_MASK and EXPONENET_MASK, what are they for ?
3) the use of &amp; in here : </p>

<pre><code>  uint32_t exponent = ( t.bits &gt;&gt; MANTISSA_WIDTH ) &amp; EXPONENT_MASK;
  uint32_t mantissa = ( t.bits  &amp;  MANTISSA_MASK );
</code></pre>

<p>Here's the code :</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdint.h&gt;
#include &lt;math.h&gt;

#define ABSOLUTE_WIDTH 31
#define MANTISSA_WIDTH 23
#define EXPONENT_WIDTH 8
#define EXPONENT_MASK 0xffu
#define MANTISSA_MASK 0x007fffffu
#define EXPONENT_BIAS 127

union float_bits {
  float f;
  uint32_t bits;
};

void print_float( FILE *output, float f ) {
  union float_bits t; t.f = f;

  uint32_t sign_bit = ( t.bits &gt;&gt; ABSOLUTE_WIDTH );
  uint32_t exponent = ( t.bits &gt;&gt; MANTISSA_WIDTH ) &amp; EXPONENT_MASK;
  uint32_t mantissa = ( t.bits  &amp;  MANTISSA_MASK );

  if( sign_bit != 0 ) {
    fprintf( output, "-" );
  }

  if( exponent &gt; 2 * EXPONENT_BIAS ) {
    fprintf( output, "Inf\n" ); /* Infinity */
    return;
  } else if( exponent == 0 ) {
    fprintf( output, "0." ); /* Zero or Denormal */
    exponent = ( mantissa != 0 ) ? exponent + 1 : exponent;
  } else {
    fprintf( output, "1." ); /* Usual */
  }

  for( int k = MANTISSA_WIDTH - 1; k &gt;= 0; --k ) {
    fprintf( output, "%d", ( mantissa &gt;&gt; k ) &amp; 1 );
  }

  if( exponent != 0 || mantissa != 0 ) {
    fprintf( output, " * 2^%d\n", (int) ( exponent - EXPONENT_BIAS ) );
  }
}

int main() {
  FILE *input  = fopen( "floating.in",  "r" ),
       *output = fopen( "floating.out", "w" );

  size_t N; float f;
  fscanf( input, "%zu", &amp;N );

  for( size_t i = 0; i &lt; N; ++i ) {
    fscanf( input, "%f", &amp;f );
    print_float( output, f );
  }

  fclose( input );
  fclose( output );
  return 0;
}
</code></pre>