Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Converting decimal to/from IEEE hex format

Carl Woll wrote:

>Robert wrote:
>>Can anyone tell me how to convert a number to/from the corresponding
>>IEEE hex floating-point representation in either 32 or 64 bits in
>>Mathematica?  For
>>example, I would want to convert 1.0 into 3F800000 (32-bit) or
>>3FF0000000000000 (64-bit), and vice-versa.  (When converting from
>>decimal to hex, if the number is not exactly representable, I would
>>want the nearest floating-point number.)  Thanks, Robert
>One idea is to use BinaryWrite and BinaryRead, although that requires 
>the use of external files. Here is one implementation:
>   tmp=OpenTemporary[BinaryFormat->True];
>   BinaryWrite[tmp,x,"Real32"];
>   tmp=Close[tmp];
>   BaseForm[BinaryRead[tmp,"Integer32"],16]
Oops, that should have been "UnsignedInteger32" not "Integer32".

Carl Woll
Wolfram Research

>RealToHex32[1.0] // OutputForm
>        16
>The conversion backwards needs a design decision on what format you want 
>the hex representation to be in.
>Carl Woll
>Wolfram Research

  • Prev by Date: Re: finite group theory w/mathematica
  • Next by Date: Re: change of variables
  • Previous by thread: Re: Converting decimal to/from IEEE hex format
  • Next by thread: Re: Converting decimal to/from IEEE hex format