Re: Scripting a text to binary digits converter

2012-01-03 Thread -=JB=-
I don't think the binaryEncode function will return the same
binary or ascii number that you get using the baseConvert
function.  The dictionary states it returns the same thing as
the pack() function used by perl.  I do not know perl so I am
not sure what they are doing.

Can anyone explain what the pack() function for perl is
used for?

The dictionary says,

charToNum(binaryEncode(B*,0111)) -- returns 127

And it does return 127 as stated.  This looks like you are taking a
binary code number and converting it to ascii but  0111 isn't
 the same binary sequence for 127 that would be used with
baseConvert so what is this 127 from?

-=JB=-



On Jan 2, 2012, at 4:16 PM, Kurt Kaufman wrote:

 More fun with LC's binaryEncode functions (see the card script):
 
 http://www.kkef.org/MIDIBuilder031212.rev
 
 It must be pretty quick to accept from user input an ascii representation of 
 a musical note, convert it to binary from which a MIDI file is constructed 
 and played, then add the input to an 
 as-yet open-ended MIDI sequence (whose current length must be properly 
 specified before attempting to update or play)- all in a fraction of a second.
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-03 Thread Ken Ray
 function convertTextToBinary varText
   --repeat with n = 1 to the number of chars of varText
   repeat for each char tChar in varText
  --put chartonum(char n of varText) into theNum
  put chartonum(tChar) into theNum
  put baseConvert(theNum,10,2) into tBaseConverted
  put char -8 to -1 of (  tBaseConverted ) into tBaseConverted
  put tBaseConverted after tConverted
   end repeat
   return tConverted
 end convertTextToBinary

Another thing you could do which *might* speed things up is to use numberFormat 
instead of parsing strings:

function convertTextToBinary varText
  set the numberFormat to 
  --repeat with n = 1 to the number of chars of varText
  repeat for each char tChar in varText
 --put chartonum(char n of varText) into theNum
 put chartonum(tChar) into theNum
 put (baseConvert(theNum,10,2)+0) into tBaseConverted  -- the +0 forces 
it to use the number format
 put tBaseConverted after tConverted
  end repeat
  return tConverted
end convertTextToBinary

You can also collapse a lot of the code (although it's less readable):

function convertTextToBinary varText
  set the numberFormat to 
  repeat for each char tChar in varText
 put (baseConvert(chartonum(tChar),10,2)+0) after tConverted
  end repeat
  return tConverted
end convertTextToBinary

Stripping a few lines may also increase speed - don't know but just a thought...

Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Web Site: http://www.sonsothunder.com/  

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-03 Thread -=JB=-
When converting ascii to binary you convert each char using the
repeat script you provided below,

repeat for each char tChar in varText

But when you want to convert the binary to ascii you need to get
eight char then convert then repeat eight chars.

How would you write the fastest repeat structure to get eight chars
then repeat until you used them all?

-=JB=-


On Jan 3, 2012, at 8:21 AM, Ken Ray wrote:

 function convertTextToBinary varText
  --repeat with n = 1 to the number of chars of varText
  repeat for each char tChar in varText
 --put chartonum(char n of varText) into theNum
 put chartonum(tChar) into theNum
 put baseConvert(theNum,10,2) into tBaseConverted
 put char -8 to -1 of (  tBaseConverted ) into tBaseConverted
 put tBaseConverted after tConverted
  end repeat
  return tConverted
 end convertTextToBinary
 
 Another thing you could do which *might* speed things up is to use 
 numberFormat instead of parsing strings:
 
 function convertTextToBinary varText
  set the numberFormat to 
  --repeat with n = 1 to the number of chars of varText
  repeat for each char tChar in varText
 --put chartonum(char n of varText) into theNum
 put chartonum(tChar) into theNum
 put (baseConvert(theNum,10,2)+0) into tBaseConverted  -- the +0 forces 
 it to use the number format
 put tBaseConverted after tConverted
  end repeat
  return tConverted
 end convertTextToBinary
 
 You can also collapse a lot of the code (although it's less readable):
 
 function convertTextToBinary varText
  set the numberFormat to 
  repeat for each char tChar in varText
 put (baseConvert(chartonum(tChar),10,2)+0) after tConverted
  end repeat
  return tConverted
 end convertTextToBinary
 
 Stripping a few lines may also increase speed - don't know but just a 
 thought...
 
 Ken Ray
 Sons of Thunder Software, Inc.
 Email: k...@sonsothunder.com
 Web Site: http://www.sonsothunder.com/
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-03 Thread Michael Doub
How's this?

Function convertBinaryToText varText
   repeat with x = 1 to the len of varText-8 step 8
  put numtochar(BaseConvert(char x to (x+7) of varText,2,10)) after 
tConverted
   end repeat
   return tConverted
end convertBinaryToText


On 2012-01-03, at 11:21 AM, Ken Ray wrote:

 function convertTextToBinary varText
  --repeat with n = 1 to the number of chars of varText
  repeat for each char tChar in varText
 --put chartonum(char n of varText) into theNum
 put chartonum(tChar) into theNum
 put baseConvert(theNum,10,2) into tBaseConverted
 put char -8 to -1 of (  tBaseConverted ) into tBaseConverted
 put tBaseConverted after tConverted
  end repeat
  return tConverted
 end convertTextToBinary
 
 Another thing you could do which *might* speed things up is to use 
 numberFormat instead of parsing strings:
 
 function convertTextToBinary varText
  set the numberFormat to 
  --repeat with n = 1 to the number of chars of varText
  repeat for each char tChar in varText
 --put chartonum(char n of varText) into theNum
 put chartonum(tChar) into theNum
 put (baseConvert(theNum,10,2)+0) into tBaseConverted  -- the +0 forces 
 it to use the number format
 put tBaseConverted after tConverted
  end repeat
  return tConverted
 end convertTextToBinary
 
 You can also collapse a lot of the code (although it's less readable):
 
 function convertTextToBinary varText
  set the numberFormat to 
  repeat for each char tChar in varText
 put (baseConvert(chartonum(tChar),10,2)+0) after tConverted
  end repeat
  return tConverted
 end convertTextToBinary
 
 Stripping a few lines may also increase speed - don't know but just a 
 thought...
 
 Ken Ray
 Sons of Thunder Software, Inc.
 Email: k...@sonsothunder.com
 Web Site: http://www.sonsothunder.com/
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-03 Thread -=JB=-
That looks real good!

-=JB=-



On Jan 3, 2012, at 12:40 PM, Michael Doub wrote:

 How's this?
 
 Function convertBinaryToText varText
   repeat with x = 1 to the len of varText-8 step 8
  put numtochar(BaseConvert(char x to (x+7) of varText,2,10)) after 
 tConverted
   end repeat
   return tConverted
 end convertBinaryToText
 
 
 On 2012-01-03, at 11:21 AM, Ken Ray wrote:
 
 function convertTextToBinary varText
 --repeat with n = 1 to the number of chars of varText
 repeat for each char tChar in varText
--put chartonum(char n of varText) into theNum
put chartonum(tChar) into theNum
put baseConvert(theNum,10,2) into tBaseConverted
put char -8 to -1 of (  tBaseConverted ) into tBaseConverted
put tBaseConverted after tConverted
 end repeat
 return tConverted
 end convertTextToBinary
 
 Another thing you could do which *might* speed things up is to use 
 numberFormat instead of parsing strings:
 
 function convertTextToBinary varText
 set the numberFormat to 
 --repeat with n = 1 to the number of chars of varText
 repeat for each char tChar in varText
--put chartonum(char n of varText) into theNum
put chartonum(tChar) into theNum
put (baseConvert(theNum,10,2)+0) into tBaseConverted  -- the +0 forces 
 it to use the number format
put tBaseConverted after tConverted
 end repeat
 return tConverted
 end convertTextToBinary
 
 You can also collapse a lot of the code (although it's less readable):
 
 function convertTextToBinary varText
 set the numberFormat to 
 repeat for each char tChar in varText
put (baseConvert(chartonum(tChar),10,2)+0) after tConverted
 end repeat
 return tConverted
 end convertTextToBinary
 
 Stripping a few lines may also increase speed - don't know but just a 
 thought...
 
 Ken Ray
 Sons of Thunder Software, Inc.
 Email: k...@sonsothunder.com
 Web Site: http://www.sonsothunder.com/   
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Scripting a text to binary digits converter

2012-01-03 Thread Bryan McCormick

Hey Ken,

Oddly your terse script ran a bit longer than the final one the group 
cobbled together by community heavy lifting. Not by much though. 1000 
repeats on both showed yours was about 13 to 20 ticks slower.


Not at all what I would have expected either.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



Scripting a text to binary digits converter

2012-01-03 Thread Bryan McCormick

Phil,

Your final version of the script ended up winning the speed race. See my 
note to Ken.


Thanks to everyone for pitching in. That was fun. Forced me to learn a 
bit about baseConvert and binaryEncode/Decode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Scripting a text to binary digits converter

2012-01-02 Thread Bryan McCormick
I have seen a number of sites that use a text to binary digits converter 
for simple encryption. Such that this is my text would be written as 
01110100011011101001011100110010011010010111001100100110110100010010011101000110010101110100


What is the simplest way of doing this in livecode? Could something like 
this also be done for photos? Or better I suppose for photos would be 
conversion to ascii text.


Thanks in advance for ideas and pointers.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread -=JB=-
The scripts below will convert between ASCII and Binary
Use a repeat on each char to convert the whole sentence.

Put the whole thing in a button to test how it works and
then rewrite the code without using ask and answer.

-=JB=-


ASCII-Bin Convert
  Convert between ASCII-Binary
  written by John Balgenorth - 7/31/08

on mouseUp
 answer convert with ASCII-Bin or Bin-ASCII
 if it = ASCII-Bin then convABin
 if it = Bin-ASCII then convBinA
end mouseUp
  
on convABin
 ask convert ASCII to Binary
 if it = empty or the result = cancel then exit to top
 put it into charConv
 put chartonum(charConv) into theNum
 put baseconvert(theNum,10,2) --into fld id 1010
end convABin

on convBinA
 ask convert Binary to ASCII
 if it = empty or the result = cancel then exit to top
 put it into theNum
 put baseconvert(theNum,2,10) into charConv
 put numtochar(charConv) --into fld id 1010
end convBinA

+++
On Jan 2, 2012, at 10:10 AM, Bryan McCormick wrote:

 I have seen a number of sites that use a text to binary digits converter for 
 simple encryption. Such that this is my text would be written as 
 01110100011011101001011100110010011010010111001100100110110100010010011101000110010101110100
 
 What is the simplest way of doing this in livecode? Could something like this 
 also be done for photos? Or better I suppose for photos would be conversion 
 to ascii text.
 
 Thanks in advance for ideas and pointers.
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 

On Jan 2, 2012, at 10:10 AM, Bryan McCormick wrote:

 I have seen a number of sites that use a text to binary digits converter for 
 simple encryption. Such that this is my text would be written as 
 01110100011011101001011100110010011010010111001100100110110100010010011101000110010101110100
 
 What is the simplest way of doing this in livecode? Could something like this 
 also be done for photos? Or better I suppose for photos would be conversion 
 to ascii text.
 
 Thanks in advance for ideas and pointers.
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread -=JB=-
That looks like a better way to go because it will also
pad the binary with the proper amount of zeros.

-=JB=-


On Jan 2, 2012, at 11:14 AM, gpb01 wrote:

 
 Bryan McCormick wrote
 
 I have seen a number of sites that use a text to binary digits converter 
 for simple encryption. Such that this is my text would be written as 
 01110100011011101001011100110010011010010111001100100110110100010010011101000110010101110100
 ...
 
 
 You can easily use the *binaryDecode()* and *binaryEncode()* functions ...
 .. see the dictionary
 
 Guglielmo
 
 --
 View this message in context: 
 http://runtime-revolution.278305.n4.nabble.com/Scripting-a-text-to-binary-digits-converter-tp4254072p4254238.html
 Sent from the Revolution - User mailing list archive at Nabble.com.
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Scripting a text to binary digits converter

2012-01-02 Thread Bryan McCormick

JB, Guglielmo

This appears to work for my purposes and is pretty speedy. See anything 
that might break?


---

function convertTextToBinary varText
   repeat with n = 1 to the number of chars of varText
  put chartonum(char n of varText) into theNum
  if theNum =64 and theNum = 127 then
 put 0baseConvert(theNum,10,2) after tConverted
  else if theNum =64 then
 put 00baseConvert(theNum,10,2) after tConverted
  else
 put baseConvert(theNum,10,2) after tConverted
  end if
   end repeat
   return tConverted
end convertTextToBinary

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread -=JB=-
When I did a quick read of binaryEncode() I was thinking
it said you could enter the number of chars you want to
convert which would eliminate the need for a repeat
structure but I did not try it and could be wrong.

-=JB=-


On Jan 2, 2012, at 12:23 PM, Bryan McCormick wrote:

 JB, Guglielmo
 
 This appears to work for my purposes and is pretty speedy. See anything that 
 might break?
 
 ---
 
 function convertTextToBinary varText
   repeat with n = 1 to the number of chars of varText
  put chartonum(char n of varText) into theNum
  if theNum =64 and theNum = 127 then
 put 0baseConvert(theNum,10,2) after tConverted
  else if theNum =64 then
 put 00baseConvert(theNum,10,2) after tConverted
  else
 put baseConvert(theNum,10,2) after tConverted
  end if
   end repeat
   return tConverted
 end convertTextToBinary
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Scripting a text to binary digits converter

2012-01-02 Thread Bryan McCormick

JB,

Well it gives some peculiar results because I clearly don't know much 
about the encoding process in terms of passing the right params.


I rewrote this to be more general. Give it a try if you like and let me 
know. It will handle carriage returns and such properly.


Seems speedy enough for me but again, I am sure it can be improved upon.

Thanks for your help, most generous of you.


--

function convertTextToBinary varText
   repeat with n = 1 to the number of chars of varText
  put chartonum(char n of varText) into theNum
  put baseConvert(theNum,10,2) into tBaseConverted
  if length(tBaseConverted) 8 then
 repeat until length(tBaseConverted)= 8
put 0 before tBaseConverted
 end repeat
  end if
  put tBaseConverted after tConverted
   end repeat
   return tConverted
end convertTextToBinary


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread gpb01

Bryan McCormick wrote
 
 JB, Guglielmo
 
 This appears to work for my purposes and is pretty speedy. See anything 
 that might break?
 
 ---
 
 function convertTextToBinary varText
 repeat with n = 1 to the number of chars of varText
put chartonum(char n of varText) into theNum
if theNum =64 and theNum = 127 then
   put 0baseConvert(theNum,10,2) after tConverted
else if theNum =64 then
   put 00baseConvert(theNum,10,2) after tConverted
else
   put baseConvert(theNum,10,2) after tConverted
end if
 end repeat
 return tConverted
 end convertTextToBinary
 
 ___
 use-livecode mailing list
 use-livecode@.runrev
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 

Just for fun I tried with a small script you function :
   put convertTextToBinary(theText) into field outField

... and the binaryDecode :
   put binaryDecode(B*, theText, binText) into numItems
   put binText into field outFieldBin

both inserted in two separate repeat to repeat the same statements 200
times, storing the millisecond to execute.

Whit your function, on my Win 7 64 bit system, I have between 60 and 70
milliseconds, with the binaryDecode() + the put statemet (/... two separate
statements/) I have between 20 and 30 milliseconds  :)

So .. the Livecode binaryDecode + the put statement is minimum *TWO* time
faster than calling your function  ;)

Guglielmo



--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/Scripting-a-text-to-binary-digits-converter-tp4254413p4254500.html
Sent from the Revolution - User mailing list archive at Nabble.com.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread Guglielmo Braguglia
You can or specify the number of character you want, or the * symbol 
which means ALL  ;)


Guglielmo


On 02.01.2012 21:36, -=JB=- wrote:

When I did a quick read of binaryEncode() I was thinking
it said you could enter the number of chars you want to
convert which would eliminate the need for a repeat
structure but I did not try it and could be wrong.

-=JB=-


On Jan 2, 2012, at 12:23 PM, Bryan McCormick wrote:


JB, Guglielmo

This appears to work for my purposes and is pretty speedy. See anything that 
might break?

---

function convertTextToBinary varText
   repeat with n = 1 to the number of chars of varText
  put chartonum(char n of varText) into theNum
  if theNum=64 and theNum= 127 then
 put 0baseConvert(theNum,10,2) after tConverted
  else if theNum=64 then
 put 00baseConvert(theNum,10,2) after tConverted
  else
 put baseConvert(theNum,10,2) after tConverted
  end if
   end repeat
   return tConverted
end convertTextToBinary

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread Jim Ault
On Jan 2, 2012, at 3:54 PM, Bryan McCormick wrote:

  put baseConvert(theNum,10,2) into tBaseConverted
  if length(tBaseConverted) 8 then
 repeat until length(tBaseConverted)= 8
put 0 before tBaseConverted
 end repeat
  end if

Alternative technique is to...

put char -8 to -1 of (  tBaseConverted ) into tBaseConverted


Jim Ault



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Scripting a text to binary digits converter

2012-01-02 Thread Bryan McCormick

JB, Jim, Guglielmo

Okay, this is the final version of the script which does seem 
considerably faster than where I started.


Thanks to all. Hope this was a useful walk-through.

Any other suggestions on ways to improve?

-

function convertTextToBinary varText
   repeat with n = 1 to the number of chars of varText
  put chartonum(char n of varText) into theNum
  put baseConvert(theNum,10,2) into tBaseConverted
  put char -8 to -1 of (  tBaseConverted ) into 
tBaseConverted

  put tBaseConverted after tConverted
   end repeat
   return tConverted
end convertTextToBinary

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread Jim Ault

On Jan 2, 2012, at 4:25 PM, Bryan McCormick wrote:

 Jim,
 
 Thanks so much. I wonder how much faster that is? And Guglielmo, I appreciate 
 you taking a crack at this. I don't get how to do the encode using your 
 approach at all since I am not familiar with the params for the BinaryEncode 
 function.
 
You could do your own bench-marking by
-
put 135898 into varText
put 100 * 1000 into loopCnt
repeat loopCnt times
   put varText  cr after veryLongList
end repeat

put the ticks into startTicks
repeat for each line LNN in veryLongList
   put convertTextToBinary(varText) into tConverted
end repeat
put the ticks - startTicks into elapsedTicks
put elapsedTicks div 60 into elapsedSeconds

get elapsedTicks   tick count
get IT  cr  elapsedSeconds   tick count
get IT  cr  loopCnt/elapsedTicks   conversions per tick
put IT into msg


Jim Ault




___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread Phil Davis
I tried using the numberFormat to pad zeroes. It worked but was about 20% slower 
(if I did my math correctly).


I got roughly a 6% speed improvement using 'repeat for each char tChar' instead 
of repeat with n = 1...


My test sample was 1000 chars.


function convertTextToBinary varText
   --repeat with n = 1 to the number of chars of varText
   repeat for each char tChar in varText
  --put chartonum(char n of varText) into theNum
  put chartonum(tChar) into theNum
  put baseConvert(theNum,10,2) into tBaseConverted
  put char -8 to -1 of (  tBaseConverted ) into tBaseConverted
  put tBaseConverted after tConverted
   end repeat
   return tConverted
end convertTextToBinary

Phil Davis



On 1/2/12 1:33 PM, Bryan McCormick wrote:

JB, Jim, Guglielmo

Okay, this is the final version of the script which does seem considerably 
faster than where I started.


Thanks to all. Hope this was a useful walk-through.

Any other suggestions on ways to improve?

-

function convertTextToBinary varText
   repeat with n = 1 to the number of chars of varText
  put chartonum(char n of varText) into theNum
  put baseConvert(theNum,10,2) into tBaseConverted
  put char -8 to -1 of (  tBaseConverted ) into tBaseConverted
  put tBaseConverted after tConverted
   end repeat
   return tConverted
end convertTextToBinary

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Scripting a text to binary digits converter

2012-01-02 Thread Kurt Kaufman
More fun with LC's binaryEncode functions (see the card script):

http://www.kkef.org/MIDIBuilder031212.rev

It must be pretty quick to accept from user input an ascii representation of a 
musical note, convert it to binary from which a MIDI file is constructed and 
played, then add the input to an 
as-yet open-ended MIDI sequence (whose current length must be properly 
specified before attempting to update or play)- all in a fraction of a second.
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode