## baseConvert woes

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

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

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

### baseConvert woes

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
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

### Re: baseConvert woes

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: 3796
Joined: Sat Feb 25, 2017 10:45 pm

### Re: baseConvert woes

I thought -hh already did that? Or maybe I'm thinking of someone else... at this stage, it is so hard to tell

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

### Re: baseConvert woes

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
Posts: 6836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

### Re: baseConvert woes

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.
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com

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

### Re: baseConvert woes

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