Re: OT How to represent a fraction in HEX?
From: Till Crueger (TillFC_at_gmx.net)
Date: 04/15/04
- Next message: Till Crueger: "Re: compile problem"
- Previous message: J.K. Becker: "Re: Problems with multiplications of doubles and/or floats"
- In reply to: Steve: "How to represent a fraction in HEX?"
- Next in thread: Dave Moore: "Re: How to represent a fraction in HEX?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 15 Apr 2004 10:24:24 +0200
On Wed, 14 Apr 2004 22:54:15 +0000, Steve wrote:
> I am having trouble finding the answer to this question, I'm thinking
> the solution must be blindingly obvious, so therefore of course I cannot
> see it.
>
> I wish to take a fraction in DEC say .4 and convert it to a HEX value. I
> also need to find a way to determine if a number is a fraction in HEX
> and convert it back to DEC.
[snip]
> I won't list them here cuz I want to solve the problems myself, I just
> happen to need to be pointed in the right direction for solving them, a
> formula or something would be nice.
There is a simple algorithm you can use for conversion of fractions. I can
give you the algorithm, so you can implement ist for yourself.
100 multiply the number by the base you are converting to
200 take the number greater than one, and use it as the
next digit in your converted number
300 discard anything greater than one
400 repeat until satisfied or left with zero
Example:
.4 * 16 = 6.4 (result 0.6)
.4 * 16 = 6.4 (result 0.66)
...
Example 2:
0.21875 * 16 = 3.5 (result 0.3)
0.5 * 16 = 8 (result 0.38)
done
When you have figured out how fractions work, it should be fairly easy to
see how this algorithm works.
Till
-- Please add "Salt and Peper" to the subject line to bypass my spam filter
- Next message: Till Crueger: "Re: compile problem"
- Previous message: J.K. Becker: "Re: Problems with multiplications of doubles and/or floats"
- In reply to: Steve: "How to represent a fraction in HEX?"
- Next in thread: Dave Moore: "Re: How to represent a fraction in HEX?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|