Forum Discussion
Altera_Forum
Honored Contributor
15 years ago --- Quote Start ---
float value = 6.8;
printf("%08X",*(unsigned int *)(&value)) ;There might be an easier way but this way does it (step by step) by extracting a pointer to the 32-bit value (&value), typecasting that pointer into a pointer to a 32-bit int (unsigned int *), then taking the value pointed to by this pointer (*). That value is passed to printf to print it as a hex value ("%08X"). --- Quote End --- I have used this solution before. If you have a good understanding of how things work at a low level, it's actually pretty straight forward. An alternative approach for the curious: union
{
float f;
unsigned int i;
}
value;
value.f = 6.8;
printf("%08X", value.i);