Thread View: comp.lang.c.moderated
1 messages
1 total messages
Started by Tom Watson
Sat, 06 Apr 1996 14:43
Hex format(s) on a floating point number
Author: Tom Watson
Date: Sat, 06 Apr 1996 14:43
Date: Sat, 06 Apr 1996 14:43
40 lines
1581 bytes
1581 bytes
I've been working on things, and wanted to get the hex representation of a
floating point number. I thought (silly me) that I could just print out
the value using a %X format in printf. Well it worked on one machine
(68000 based) and didn't on another (RISC type) where arguments were
passed in registers (and floating point registers were different from
integer registers).
My question: Can I print out a floating point number (probably elevated
to 'double' status, or better) with a %X type format?
[No. I'd loop with unsigned char and %#2X. -mod]
Example program follows (which has the eventual solution):
>>>>>
#include <stdio.h>
int main (void)
{
float pie = 3.14159; /* Please excuse my approximation */
printf ("Pi is %f in floating point, and 0x%08X, 0x%08X, 0x%08X in hex\n",
pie, pie);
/* On one machine things got promoted to long double (nee extended) thus
the three hex formats. */
{
union {unsigned int hex; float flt;} xx;
xx.flt = pie;
printf ("Pi is now %f in floating point, and 0x%08X in hex\n",
xx.flt,xx.hex);
}
return 0;
}
<<<<<
--
Tom Watson
tsw@3do.com (Home: tsw@johana.com)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads