LZW compression and binaryEncode

Dar Scott dsc at swcp.com
Sun Apr 17 16:53:00 EDT 2005


On Apr 17, 2005, at 2:38 PM, jbv wrote:
> But now I need to convert the output serie of index into binary
> data... Anyone familiar with this ?
> I guess I need to use binaryEncode, but how to set up parameters ?

Normally, we think of a value in Transcript as a sequence of 
characters.  When we work with binary we can view each character as 
that for an 8-bit encoding, that is, a byte.  Thus, a value can be 
viewed as a sequence of bytes.  Just as we can concatenate characters 
with &, we an concatenate what we consider to be bytes sequences the 
same way.

To get at the numerical value of the byte, you can use charToNum().  
You can also use numToChar() as the inverse.

You can also use binaryEncode() and binaryDecode().  Most formats are 
in host order and so are of limited utility.  However, some formats, 
such as "N", are big endian.  If you need small endian formatting, just 
reverse.  There are some formats missing, so you would want to build up 
a few simple functions to help.

For example,

    put binaryEncode("N",566) into aLen

would put 4 bytes (chars) into aLen.

Dar

-- 
**************************************************
     DSC (Dar Scott Consulting & Dar's Lab)
     http://www.swcp.com/dsc/
     Custom libraries (with externals, if needed)
**************************************************



More information about the use-livecode mailing list