Tapio Kelloniemi wrote:
I didn't find this one from the FAQ:
I'm writing an input parser for numbers. Everything else is piece
of Cake, except how to parse real numbers that are in some other
base than 10, eg. 3A.B4 in base 12. This can be done for
integers using the strtoxx ISO C functions, but there is no base
argument for the float/double versions. How could I then print
out reals in non-base 10 format?
For input, assuming you already know what the base is, parse the
integer portion with strtoul. That leaves a pointer to the
termination character, which you can check to be a '.'. Advance
the pointer. Check it points to a digit in the appropriate base.
Parse the remainder. The returned value represents itself divided
by base raised to the number of chars consumed. Combine
components.
Output of the integer portion is easy. The fractional portion can
be handled by successive multiplications by the base and
converting the integer portion of that into a digit.
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!