Converting Hexadecimal in Binary

Dar Scott dsc at swcp.com
Sat Jan 10 13:24:00 EST 2004


On Saturday, January 10, 2004, at 10:39 AM, Alejandro Tejada wrote:

>> repeat with i = 1 to length(asd) step 6
>> put null & unhex(char i to i+5 of asd) after qwe
>> end repeat
>
> This is 200% faster than the original!!!

>> binaryEncode("H*",h)

This might be faster yet:

repeat with i = 1 to length(asd) step 6
    put null & binaryEncode("H*", char i to i+5 of asd) after qwe
end repeat

I have a couple binaryEncode and binaryDecode enhancements suggested on 
bugzilla, but I'm not sure whether these would allow doing this in one 
call to binaryEncode().  That would be cool if that was possible.

>
>> The problem is inserting the extra null every three
>> bytes, otherwise this could be done in one step.
>> It is easy to get data from an image in three bytes
>> per pixel, the export as "paint" provides data in P6
>> format, and that can be trimmed to get
>> three bytes per pixel.
>
> This is very interesting.
> Do you have a function able to export an image from
> MC/RR as RGB hexadecimal data?

No, but here are a couple ideas.

1.
You can do the inverse of the above with imageData

or

2.

A.  export as paint to a variable
     That has a text header with 3-byte binary RGB
     See:
     http://astronomy.swin.edu.au/~pbourke/dataformats/ppm/

B.  Break out the binary pixel data from the text header
     You might try a regex that would work on any
     P6 data, or by looking at the header you might
     find that something like 'line 4 to -1" or some
     other method would work for Rev P6 data.

C.  Apply the previously mentioned hex() function
     only one time to the binary data.

D.  Done.

Both of these ignore mask and alpha.  The latter could be expanded to 
provide size data.

Dar Scott



****************************************
     Dar Scott Consulting
     http://www.swcp.com/dsc/
     Programming Services
****************************************



More information about the use-livecode mailing list