#include <limits.h>
#include <string.h>
#include <stdio.h>
 
#define C_ASSERT(expr) extern char CAssertExtern[(expr)?1:-1]
 
C_ASSERT(CHAR_BIT == 8);
C_ASSERT(sizeof(float) == 4);
C_ASSERT(sizeof(int) == 4);
 
float div(int x, unsigned n)
{
  float res;
  unsigned e = 0;
  unsigned sign = x < 0;
  unsigned m = sign ? -x : x;  
 
  if (m)
  {
    while (m >= (1u << 24))
      m >>= 1, e++;
 
    while (m < (1u << 23))
      m <<= 1, e--;
 
    e += 0x7F + 23;
 
    e -= n; // divide by 1<<n
 
    m ^= 1u << 23; // reset the implicit 1

    m |= (e & 0xFF) << 23; // mix in the exponent
 
    m |= sign << 31; // mix in the sign
  }
 
  memcpy(&res, &m, sizeof m);
 
  return res;
}
 
void Print4Bytes(unsigned char buf[4])
{
  printf("%02X%02X%02X%02X ", buf[3], buf[2], buf[1], buf[0]);
}
 
int main(void)
{
  int x = 0x35AA53;
  int n;
  for (n = 0; n < 31; n++)
  {
    float v1 = (float)x/(1u << n);
    float v2 = div(x, n);
    Print4Bytes((void*)&v1);
    printf("%c= ", "!="[memcmp(&v1, &v2, sizeof v1) == 0]);
    Print4Bytes((void*)&v2);
    printf("%14.6f %14.6f\n", v1, v2);
  }
  return 0;
}
