Article View: comp.lang.c.moderated
Article #2534Hex format(s) on a floating point number
From: 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)
Technical Details
Message-ID:
<4k5vtu$a4m@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: tsw@3do.com (Tom Watson) Newsgroups: comp.lang.c.moderated Subject: Hex format(s) on a floating point number Date: 6 Apr 1996 08:43:10 -0600 Organization: The 3DO Corporation Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4k5vtu$a4m@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com