[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: converting arbitrary long decimals to hex?
- From: KHMan <keinhong@...>
- Date: Sat, 09 Jan 2010 01:58:50 +0800
Norbert Kiesel wrote:
I'm trying to convert arbitrary long decimals (encoded as a string of
digits) to it's hex representation (i.e. a string of hexadecimal
digits). For short decimals, format('%x') is the way to go. That
looses out however for e.g. '5766297887677882160' because we loose
precision when it's internally converted to a (floating point) number:
it returns '50060160b0202000' instead of '50060160b0201f30'.
So please help me out. Here is what I came up with, is that correct or
is there a better/faster way to do it (I know that BigNum can do it, but
this is not pure Lua).
At first glance, I don't believe calculating partial results from
left to right in this way works... have you actually tried the code?
for i = 1, #decimal do
Tons of FLOSS arbitrary precision code around, I think they are
worth a look.
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia