Encoding int value as an IEEE-754 float (binary32)

C has the “union” to handle this type of view of data:

typedef union {
  int i;
  float f;
 } u;
 u u1;
 u1.f = 45.6789;
 /* now u1.i refers to the int version of the float */
 printf("%d",u1.i);

Leave a Comment