using Baseconvert to convert decimal to binary
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
using Baseconvert to convert decimal to binary
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
Re: using Baseconvert to convert decimal to binary
Hi gstrekkie,
Welcome to the forum!
Normally I wouldn't just hand you the script except that there is a trick in it
that add 0... wierd.
Simon
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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: using Baseconvert to convert decimal to binary
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!
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: using Baseconvert to convert decimal to binary
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: using Baseconvert to convert decimal to binary
That Totally worked and makes it very easy to Pad some binary numbers to a specific length. Thanks Simon & Richard.....