in reply to Working with BIG binary fields

Here's another approach, based on my guess that you're processing 'text' strings (of any length: 16 hex bytes used for example) consisting of any combination of hex digits and whitespace. (Assumes: '01' == 0b00000001 and '0304' == 0b0000001100000100 and etc.)

>perl -wMstrict -le "my $str = qq{ 01 02 03 \n 04 00 E0 0a 00 00 00 00 00 00 00 00 00 \n}; (my $bits = $str) =~ s{[^[:xdigit:]]}{}xmsg; $bits = unpack 'B*', pack 'H*', $bits; my @ones_offsets; push @ones_offsets, $-[1] while $bits =~ m{(1)}xmsg; print qq{'$str'}; print qq{'$bits'}; print qq{no one bits found} unless @ones_offsets; print qq{1 bit at offset $_} for @ones_offsets; " ' 01 02 03 04 00 E0 0a 00 00 00 00 00 00 00 00 00 ' '000000010000001000000011000001000000000011100000000010100000000000000 +00000000000000000000000000000000000000000000000000000000000' 1 bit at offset 7 1 bit at offset 14 1 bit at offset 22 1 bit at offset 23 1 bit at offset 29 1 bit at offset 40 1 bit at offset 41 1 bit at offset 42 1 bit at offset 52 1 bit at offset 54

If BrowserUk's guess is right and you already have the data as raw binary string (say, in $bits), just drop the
    $bits = unpack 'B*', pack 'H*', $bits;
statement and all before it, and change that statement to
    $bits = unpack 'B*', $bits;
instead (tested).

Replies are listed 'Best First'.
Re^2: Working with BIG binary fields
by Anonymous Monk on Sep 21, 2010 at 12:27 UTC
    GREAT !!!
    Thanks you very much, I work with raw binary data and your code -modified according your last remark- returns me exactly what I wanted.

    This is "Grand Art"

    I am writing PERL scripts (big ones) since years in order to help me in my daily work as Head of NOC. I spent 4 hours this morning to NOT understand your code (the 1st one), I gave up I tryed the second one with immediate succes (in results, not in understanding) .
    I thought I "can" write PERL, now I am really down and full of doubts.

    Thanks a lot

    Juju