News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Ling Long Kai Fang BigNum to ASCII String

Started by dedndave, September 23, 2009, 10:00:53 PM

Previous topic - Next topic

raymond

Quoteseriously, N-bit binary number has Trunc(N*Log10(2))+1 decimal digits

It has a maximum of Trunc(N*Log10(2))+1 decimal digits.
It has a minimum of Trunc(N*Log10(2)) decimal digits.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

MichaelW

QuoteMichael,
we are talking about the maximum length
no need to generate random numbers - just set all the bits to 1

I didn't see that stated anywhere. Testing the formula for the maximum length is trivial for small bit lengths, and the value that you specified is much closer to the mean length, without leading zeros and over the full range of values, than to the maximum, so I guessed that the goal was the mean length.

And my backup excuse :lol is that I did this after I woke up in the middle of the night and could not immediately go back to sleep, but it was too early to start in with the coffee.
eschew obfuscation

drizz

Quote from: raymond on September 25, 2009, 03:56:39 PM
Quoteseriously, N-bit binary number has Trunc(N*Log10(2))+1 decimal digits

It has a maximum of Trunc(N*Log10(2))+1 decimal digits.
It has a minimum of Trunc(N*Log10(2)) decimal digits.

lol I wrote "(maximum)" at the end of sentence but deleted it before posting... ::)
Next time i'll remember to be precise :)
The truth cannot be learned ... it can only be recognized.

dedndave

Michael - you don't need any "excuse" around here - lol
we are all half-crazy, afterall
besides, you have contributed much to our progress, so we can't really complain - lol

i have written a small program that grabs maximum allocatable process heap,
splits it into integer/buffer space, fills the integer with 1's and cranks
the integer is 611,607,020 bytes long
the output buffer space is 1,472,896,500 bytes (i made it a tad bigger than it needed to be - lol)
it is cranking on the decimal string, now
i will let you know how many decimal digits it makes (as soon as the dang thing finishes - lol)

dedndave

...still cranking...
lol
i gave up on that one - lol
too ling long
i may play with some numbers and see what size returns in a practical length of time

dedndave

here are some practical sizes...

integer length: 262,144 bytes
decimal string: 631,306 bytes
Drizz formula: 631,306 bytes

integer length: 524,288 bytes
decimal string: 1,262,612 bytes
Drizz formula: 1,262,612 bytes

1Mb takes more than 10 minutes to crank out a result
at least we know what sizes are practical - lol

my appologies Ray - i must have been punching the buttons wrong or something
your log formula seems to work ok
Drizz's little touch makes it perfect for calculating required buffer length

dedndave

dialing in on it by the bit...

All 1 bits

4194296 Integer Bits 1262609 Decimal Digits
4194297 Integer Bits 1262610 Decimal Digits
4194298 Integer Bits 1262610 Decimal Digits
4194299 Integer Bits 1262610 Decimal Digits
4194300 Integer Bits 1262611 Decimal Digits
4194301 Integer Bits 1262611 Decimal Digits
4194302 Integer Bits 1262611 Decimal Digits
4194303 Integer Bits 1262612 Decimal Digits
4194304 Integer Bits 1262612 Decimal Digits

Single 1 bit

4194296 Integer Bits 1262609 Decimal Digits
4194297 Integer Bits 1262609 Decimal Digits
4194298 Integer Bits 1262610 Decimal Digits
4194299 Integer Bits 1262610 Decimal Digits
4194300 Integer Bits 1262610 Decimal Digits
4194301 Integer Bits 1262611 Decimal Digits
4194302 Integer Bits 1262611 Decimal Digits
4194303 Integer Bits 1262611 Decimal Digits
4194304 Integer Bits 1262612 Decimal Digits

UtillMasm

Kai Fang == extraction of a root; evolution

Ling Long == a small, cabinet, smart way

it's too old,,,, this just a literal translation.

dedndave

cool - that helps  :U
what i found using the "traditional" Chinese online translators was that ling/long was a ladder(or lattice)/solution
"smart way" may be what he meant
"extraction of a root" is, i am sure what was meant in the original text
the equation may be used for that, as well

cobold

Quote from: dedndave on September 25, 2009, 02:34:46 PM
i checked it against the length of a 65,536 byte integer, which is 157,287 decimal digits

Shouldn't that be 157,827 decimal digits for a 65,536 byte unsigned integer with all bits == 1 ?
I mean either it's a typo or the routine gives wrong results? - I checked this with a routine of mine and my result is 157,827 decimal digits for a 64k integer

best regards
cobold

dedndave


dedndave

ok guys
i got version 2 up and running
i need to do some clean-up and finish the documentation
looks like i shaved almost 3,000 clock cycles off the 1024-bit integer all 1's test   :bg
and - the output is left justified in the buffer field
that ascii conversion loop was tricky - lol
i will post asap

dedndave

uh oh
i was testing version 2 and found a design flaw
some negative values are displayed incorrectly
i went back to see if version 1 had the same flaw - and it does
i appologize if this has caused any inconvenience
i thought i had tested it thoroughly
the values that are displayed incorrectly were either not tested or escaped my attention
i have removed the version 1 d/l and will let you know what i find

as you know, it is extremely impractical to test all the possible values

dedndave

ok i have found the troubles
to evaluate (signed) negative values, i invert the input values as they are read and add one to the accumulator
the problem was - i was adding one to the accumulator prior to evaluating the input value
that means - for input values larger than a dword, that 1 gets multiplied up
smaller values do not get multiplied
the fix is to add the 1 AFTER evaluation is complete (actually, during evaluation of the last input dword)
i will fix version 1 and post the d/l asap
again, i am sorry if this caused any problems for you
Dave

dedndave

the mistake has been fixed
i have tested and verified a larger variety of values
the d/l is in the first post of the thread, and here...
http://www.masm32.com/board/index.php?action=dlattach;topic=12363.0;id=6725