in reply to Reversing chunks in a string (bits of byte in a bitstring)


Here is one way.
#!/usr/bin/perl -wl my $str1 = "1101000010101111"; my $str2 = join "", unpack "b8b8", pack "B*", $str1; print for $str1, $str2; __END__ Prints: 1101000010101111 0000101111110101

For this sort of task pack is usually the fastest method but to be sure you should benchmark it against the other solutions.

--
John.