Well, the fastest way to make the basic conversion 8-bit to 8-bit (that 9th bit is always one according to your spec), is tr///; That does byte for byte translations on strings very quickly. (You'd need to unwrap the following):
tr[\x00-\xff][
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
\x00UT\x01P\x05\x04Q(\x15\x14)\x10ED\x11
];
The above would have to be coded as a single line as the look up tables are built at compile time. It makes it difficult to format it nicely. evaling a sub into existance at runtime is one possibility.
But that is a very strange encoding process as there appears to be no way to reverse it! The 256 input bytes result in just 16 output values.
Converting those encoded bytes to the 16-bit values with the two constant 1 bits set, is just a case of or-ing them with the appropriate 16-bit value, possible left shifting first. But the right combination of constant value and shifting will depend upon the endian-ness of the source and target machines and whether they are the same or different.
When you say "send this 2 byte packet", do you mean the program doing the convertion will do the sending (via socket or port?). Or will you write the data to a file and then use another program to send it?
If the latter, then yu can savce 50% of the disk space by writing the encoded 8-bit data to file, and adding the two constant bits in the program doing the sending.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|