From: Peter Barada <peter@th...>  20031109 05:42:05

>I got a float single, manage it in a binary form in an unsigned int. And >wish to recover the float form. >The magnitudes range never be greather than +/ 32k. > >to manage a float we can do: Sign * 2^m * 1.F ( where m = E 127 and F >= mantissa). > >To reconstruc with: > > r = 0.0 /* this is float */ > n = Mantisa /* unsigned, mantissa constructed in binary */ > n = n  0x3F800000; /* this meant 'or' with E127 = 0, positive */ > >now try to 'or' the binary equiv. in the float variable > > r = r  n; /* meant 1.F */ > >compiler cant manage float and unsigned 'or', maybe assuming not both 32 >bits long ? >the next cant be managed too, of course: > > r = 2^m * r; /* meant 2^m * 1.F */ > >How can I construct a float from a binary unsigned equiv. value ? Use a union to hold bothe the float and the binary representation of the float: float transmute(unsinged int mantissa) float f; union { float f; unsigned int i; } fi; fi.i = mantissa; /* Mantissa is a value in the lower 23 bits , a fraction where 0x007ffff is 1 ulp less than one. */ fi.i = 0x3f800000; /* set exponent and sign bits */ f = fi.f; /* interpret fi.i as binary representaiton of a float */ return(f); }  Peter Barada peter@... 