in reply to Re: Convert ASCII string to 7-bit binary string
in thread Convert ASCII string to 7-bit binary string

A slight variant that unpacks in the right order and drops the reverse for the expense of a second unpack inside a map.

$ perl -Mstrict -Mwarnings -E ' my $out; $out .= $_ for map { unpack q{xA7}, $_ } unpack q{(B8)*}, q{4B3A}; say $out;' 0110100100001001100111000001 $

Not as succinct but possibly slightly easier to work out what is going on because it is not immediately clear that your b7 format will drop the last (most significant) bit before you reverse the bits into the correct order.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: Convert ASCII string to 7-bit binary string
by AnomalousMonk (Archbishop) on Oct 28, 2015 at 12:55 UTC

    Inspired by kennethk's second approach above, this avoids the reversible complexity of either  '(B8)*' or  '(b7)*' in favor of  'C*' simplicity:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $out; $out .= sprintf '%07b', $_ for unpack 'C*', '4B3A'; print qq{'$out'}; " '0110100100001001100111000001'


    Give a man a fish:  <%-{-{-{-<