#include
int main () {
float a = 123.0;
unsigned char ch, *cp;
ch = 0xff;
cp = (unsigned char *) &a;
printf (\"%02x\", ch&(*(cp+3)));
pri
See Wikipedia: http://en.wikipedia.org/wiki/Single_precision_floating-point_format, which describes single precision floating point (a typical C float
, but depends on the compiler) as a 1-bit sign, 8-bit biased exponent, and 24-bit mantissa (23-bits stored).
For your example:
123.0 = 42f60000hex = 0 10000101 11101100000000000000000bin
1-bit sign = 0 (indicating positive number)
8-bit biased exponent = 10000101bin = 133dec - 127dec = 6dec
23-bit mantissa = 11101100000000000000000bin = 1.111011bin (note implied leading 1)Converting 1.111011bin x 26dec = 1111011.0bin = 123.0dec