[dba-Tech] Conversion of REAL decimal numbers to Hex

Steve Erbach erbachs at gmail.com
Tue Mar 21 12:05:20 CST 2006


Josh,

I hear you on the cutoff.  I tried converting by hand the decimal
number 1.07 to hex and got 1.11EB85 before I stopped.

I did find an on-line calculator:

http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html

Apparently, there's a standard way to represent floating point numbers
in hex, but the resulting Hex number doesn't have a "decimal" point. 
For example, 1.07 (decimal) comes out as 3FF11EB851EB851F using a
64-bit double precision hex number.  You can see the string "11EB85"
in that number, the same that I came up with manually, but I'm still
puzzling over the beginning 3FF.

The site has the complete JavaScript code for the conversion, so maybe
I can figure out what the 3FF is for.

Thanks,

Steve Erbach
http://TheTownCrank.blogspot.com


On 3/21/06, Josh McFarlane <darsant at gmail.com> wrote:
> On 3/21/06, Steve Erbach <erbachs at gmail.com> wrote:
> > Dear Group,
> >
> > There are about a jillion decimal to hex converters on the web.  But
> > what I'm looking for is a converter that will handle decimal numbers
> > with decimals.  That is, convert 1.0625 (decimal) to 1.1
> > (hexadecimal).  I can write one that recursively takes the remainder
> > from a division by higher and higher powers of 16 and dividing the
> > remainder the the next higher power of sixteen, etc.  Just wondered if
> > any of you had seen such a utility.
>
> Are you looking for something for integration into a system, or
> something for personal use?
>
> Problem with trying to represent a floating decimal based number in a
> different system is that you can't always get an exact value for the
> number you want to represent, so any cnoversion utility would have to
> have a cutoff point.
>
> I've tinkered with a C++ app to do it for me, but it's not anywhere
> near professional, just a toy.
>
> --
> Josh McFarlane



More information about the dba-Tech mailing list