in reply to Interleaving bytes in a string quickly
It's a repeated task for many buf-strings of fixed length to convert?
If yes, you may wanna try to pack(unpack $string) such that each byte is transformed to the highbyte of a 16-bit word and the lowbyte is 0.
Then just "or" with constant string with the "fixed byte" at lowbyte positions (that are 1,3,5..., the odd indexes).
Should be faster since you avoid looping bytewise on the perl level... but I have no time to try it out now.
Cheers Rolf
Update: corrected
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interleaving bytes in a string quickly
by LanX (Saint) on Feb 26, 2010 at 15:03 UTC |