in reply to Help displaying binary data bit-by-bit in binary notation

Have you tried the pack function (and its counterpart unpack)? If I understood your question correctly, that might be what you're looking for. Here's a quick example:

use strict; use warnings; my $string = 'a'; print 'unpack b = [', unpack( "b*", $string ), "]\n";
This prints unpack b = [10000110].

If you want something else, please be more specific.

HTH

Replies are listed 'Best First'.
Re^2: Help displaying binary data bit-by-bit in binary notation
by unixhome (Novice) on Jun 15, 2006 at 03:00 UTC
    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

      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.