Most efficient way to convert data to binary/base2

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

Most efficient way to convert data to binary/base2

Post by istech » Sat Aug 08, 2015 10:48 am

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Sat Aug 08, 2015 2:49 pm

Hi.

Does "binaryEncode" do what you need?

Craig Newman

istech
Posts: 211
Joined: Thu Sep 19, 2013 10:08 am

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

Post by istech » Mon Aug 10, 2015 10:13 am

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Mon Aug 10, 2015 2:55 pm

Ah.

Now look up the "baseConvert" function.

Craig

Post Reply