in reply to Re: Help displaying binary data bit-by-bit in binary notation
in thread Help displaying binary data bit-by-bit in binary notation

HTH: Yes, your unpack b is close to what I need if we could only get it to display the binary number one bit at-a-time. Like:
unpack b = 1 0 0 0 1 1 0
Thanks, RV

Replies are listed 'Best First'.
Re^3: Help displaying binary data bit-by-bit in binary notation
by bobf (Monsignor) on Jun 15, 2006 at 03:07 UTC

    Since unpack returns a string, simply add a bit (pun intended) of split and you're done:

    my $bin_str = unpack( "b*", $string ); print join( "\n", split( //, $bin_str ) );

    Updated output:

    unpack b = [10000110] 1 0 0 0 0 1 1 0

      The following also works:

      my $bin_str = unpack( "b*", $string ); print join( "\n", $bin_str =~ /(.)/g );

      It avoids split plus a (magical) regexp when just a regexp will do.

      It avoids split // which confuses Text::Balanced.

        How does Text::Balanced enter this scenario? What's the problem?

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart