using Baseconvert to convert decimal to binary

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
gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

using Baseconvert to convert decimal to binary

Post by gstrekkie » Wed Aug 21, 2013 12:00 am

Hi I am playing with livecode for about a week now and I am trying to figure out how I can baseconvert(fieldLen,10,2) to return a binary representation of a decimal number. the problem is that it seems to truncate the leading zeros. Optimally I would like the ability to set the numberformat to a specific bit size (i.e. 9 Bits) but I cant seem to wrap my head around doing this correctly and I am sure I am missing something. any answers or pointing to the right direction would be appreciated. TIA

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: using Baseconvert to convert decimal to binary

Post by Simon » Wed Aug 21, 2013 1:00 am

Hi gstrekkie,
Welcome to the forum!

Normally I wouldn't just hand you the script except that there is a trick in it

Code: Select all

on mouseUp
   set the numberformat to "#########"
   put the baseConvert(26,10,2) into temp
   add 0 to temp -- dang the numberformat needs a caulation
   put temp
end mouseUp
that add 0... wierd.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: using Baseconvert to convert decimal to binary

Post by gstrekkie » Wed Aug 21, 2013 1:16 am

So thats why numberformat wasnt working for me. well thanks for the quick reply and the heads up, there are a number of things I need to get acclimated to apparently. I will post if it works for me and hopefully anyone else that might run into the issue. Thanks again!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: using Baseconvert to convert decimal to binary

Post by FourthWorld » Wed Aug 21, 2013 1:29 am

You might try the binaryEncode function.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

gstrekkie
Posts: 27
Joined: Tue Aug 20, 2013 11:43 pm

Re: using Baseconvert to convert decimal to binary

Post by gstrekkie » Wed Aug 21, 2013 1:30 am

That Totally worked and makes it very easy to Pad some binary numbers to a specific length. Thanks Simon & Richard.....

Post Reply