spurperl has asked for the wisdom of the Perl Monks concerning the following question:
I have a string of 0s and 1s, for instance "1101000010101111". I want to reverse each group of 8 chars in it. For the above example: "0000101111110101"
The application is a string of bits, and the bits of each byte must be reversed.
I'm looking for the fastest way to achieve this, on strings of small length (up to a few hundred chars). The obvius solution, which is pretty fast is with substr() on each 8 bits (in a for loop). Any better ideas ?
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reversing chunks in a string (bits of byte in a bitstring)
by broquaint (Abbot) on Feb 16, 2004 at 14:28 UTC | |
|
Re: Reversing chunks in a string (bits of byte in a bitstring)
by Tomte (Priest) on Feb 16, 2004 at 14:52 UTC | |
|
Re: Reversing chunks in a string (bits of byte in a bitstring)
by belg4mit (Prior) on Feb 16, 2004 at 14:36 UTC | |
|
Re: Reversing chunks in a string (bits of byte in a bitstring)
by jmcnamara (Monsignor) on Feb 16, 2004 at 20:07 UTC |