To see the data that encodes a floating-point object, one can use:
#include <inttypes.h> // For printf format PRIx32.
#include <stdint.h> // For uint32_t.
#include <string.h> // For memcpy.
...
// Copy bytes of float num into bytes of uint32_t x.
uint32_t x;
_Static_assert(sizeof x == sizeof num, "num must be 32 bits."); // Check size.
memcpy(&x, &num, sizeof x);
// Print x as a hexadecimal numeral.
printf("0x%" PRIx32 "\n", x);
The value in x
is a number. Whether it is printed as hexadecimal or decimal, the same value is printed, just in different bases. This does not change the number in x
. Printing it in hexadecimal is more useful for humans to be able to see the components of the floating-point format in the display. But the value is the same regardless of whether it is shown in hexadecimal or decimal.