baseConvert woes

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

baseConvert woes

Post by Ledigimate » Wed Dec 19, 2018 8:24 pm

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
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

Re: baseConvert woes

Post by Ledigimate » Wed Dec 19, 2018 8:40 pm

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
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: baseConvert woes

Post by bogs » Wed Dec 19, 2018 9:38 pm

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.
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9663
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: baseConvert woes

Post by dunbarx » Wed Dec 19, 2018 11:15 pm

Hermann did indeed write a "long" addition, subtraction, multiplication and division gadget several months ago

It's around here somewhere.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9837
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: baseConvert woes

Post by FourthWorld » 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

Re: baseConvert woes

Post by Ledigimate » Thu Dec 20, 2018 1:35 pm

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.
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

Post Reply

Return to “Talking LiveCode”