The question is in the title. Say, for a 64-bit machine.
I want to know how the floating number is represented because I would like to know the result of
1.002 * 10^3 - 1.000 * 10 ^3
in machine representation. Thanks for your ideas.
The question is in the title. Say, for a 64-bit machine.
I want to know how the floating number is represented because I would like to know the result of
1.002 * 10^3 - 1.000 * 10 ^3
in machine representation. Thanks for your ideas.
If you are you looking for the representation of a float
value in memory, then you can write down a small C program to reveal the answer. Taking the value specified in your question, for example:
float f = (float)(1.002*1000-1.000*1000);
char* p = (char*)&f;
int i;
// Little Endian
for (i=0; i<sizeof(f); i++)
printf("%.2X",p[i]);
// Big Endian
for (i=sizeof(f)-1; i>=0; i--)
printf("%.2X",p[i]);
Please note that the "%.2X"
string is correspondent with CHAR_BIT
being equal to 8
, and should generally be set as "%.NX"
, with N
being equal to CHAR_BIT/4
.