Page 1 of 1

baseConvert woes

Posted: Wed Dec 19, 2018 8:24 pm
by Ledigimate
Dear forum

The baseConvert function tells me that the numbers 3614123224 and 7909090520 has the same binary representation! WHY??

Code: Select all

put baseConvert("3614123224", 10, 2) is baseConvert("7909090520", 10, 2) -- yields true
This has been causing me huge frustration. Can someone explain what's going on here?

Regards,

Gerrie

Re: baseConvert woes

Posted: Wed Dec 19, 2018 8:40 pm
by Ledigimate
Never mind.

I see the dictionary says baseConvert can only handle numbers between zero and 4,294,967,295 (2^32 - 1).
The number 7909090520 is thus too large for baseConvert to handle. I guess I'll have to write my own function to convert larger numbers!

Gerrie

Re: baseConvert woes

Posted: Wed Dec 19, 2018 9:38 pm
by bogs
I thought -hh already did that? Or maybe I'm thinking of someone else... at this stage, it is so hard to tell :?

There was this multipage thread about large numbers, maybe the answers are in there.

Re: baseConvert woes

Posted: Wed Dec 19, 2018 11:15 pm
by dunbarx
Hermann did indeed write a "long" addition, subtraction, multiplication and division gadget several months ago

It's around here somewhere.

Craig

Re: baseConvert woes

Posted: Thu Dec 20, 2018 4:18 am
by FourthWorld
What does the number represent? Is it an actual quantity, or a decimal representation of byte values? If the latter, the binaryEncode and binaryDecode functions may help, since they can operate on a series of values in one pass, with lots of conversion options.

Re: baseConvert woes

Posted: Thu Dec 20, 2018 1:35 pm
by Ledigimate
FourthWorld wrote:
Thu Dec 20, 2018 4:18 am
What does the number represent? Is it an actual quantity, or a decimal representation of byte values? If the latter, the binaryEncode and binaryDecode functions may help, since they can operate on a series of values in one pass, with lots of conversion options.
Kind of both. The number is an actual quantity calculated as the sum of four 32-bit integers, and only one of the four integers is the decimal representation of a 4-byte chunk of binary data. I'm trying to write a hashing algorithm.

But not to worry, as I don't actually need to convert the REAL sum of the four integers to its bit-representation. I only need the bit-representation of (theSum bitAnd 4294967295), which leaves a 32-bit integer. So the baseConvert function will work just fine.