Page 1 of 1

Most efficient way to convert data to binary/base2

Posted: Sat Aug 08, 2015 10:48 am
by istech
Hi all,

I am trying to find the most efficient way to convert data whether it be text or image data into base 2 binary. However the methods I have research don't seem to be very efficient and was hoping for another method or function to use.

current solution:

chartonum(data)
baseconvert(data,10,2)

and loop through each char add padding etc.

What would be perfect is the base64encode function in livecode but for base2. Any help with this would be great thank you all.

Re: Most efficient way to convert data to binary/base2

Posted: Sat Aug 08, 2015 2:49 pm
by dunbarx
Hi.

Does "binaryEncode" do what you need?

Craig Newman

Re: Most efficient way to convert data to binary/base2

Posted: Mon Aug 10, 2015 10:13 am
by istech
I'm not sure binaryencode() works that way.

From the dictionary example: charToNum(binaryEncode("B*","01111111")) -- returns 127

But how do you do the reverse of this? To get the ASCII/number or char into binary/base2 using this function.

Still looking into it. Maybe someone can shed some more light on it.

Re: Most efficient way to convert data to binary/base2

Posted: Mon Aug 10, 2015 2:55 pm
by dunbarx
Ah.

Now look up the "baseConvert" function.

Craig