unsigned int exp : 8; // middle bits
unsigned int sign : 1; // highest bit
}float_bit;
}float_value;
一个简单的测试代码:
[cpp]
#include
#define PRINT_D(intValue) printf(#intValue" is %d\n", (intValue));
#define PRINT_F(floatValue) printf(#floatValue" is %f\n", (floatValue));
// IEEE 754 single floating number's format(intel little-endian mode)
typedef union
{
// float value
float f;
// intel bits mode that stands for float value
struct
{
unsigned int dot : 23; // low bits
unsigned int exp : 8; // middle bits
unsigned int sign : 1; // highest bit
}float_bit;
}float_value;
int main(int argc, char **argv)
{
float_value fv;
fv.float_bit.sign = 1;
fv.float_bit.exp = 128;
fv.float_bit.dot = 0;
PRINT_F(fv.f);
return 0;
}
#include
#define PRINT_D(intValue) printf(#intValue" is %d\n", (intValue));
#define PRINT_F(floatValue) printf(#floatValue" is %f\n", (floatValue));
// IEEE 754 single floating number's format(intel little-endian mode)
typedef union
{
// float value
float f;
// intel bits mode that stands for float value
struct
{
unsigned int dot : 23; // low bits
unsigned int exp : 8; // middle bits
unsigned int sign : 1; // highest bit
}float_bit;
}float_value;
int main(int argc, char **argv)
{
float_value fv;
fv.float_bit.sign = 1;
fv.float_bit.exp = 128;
fv.float_bit.dot = 0;
PRINT_F(fv.f);
return 0;
}
输出:
[plain]
fv.f is -2.000000