Here's an automated way to create the lookup table. Bit-counting function assumes data passed as raw binary string of any length, but test statements show a way to convert from hex-digit text string if it isn't.

>perl -wMstrict -le "my @setbits; for my $byte (0 .. 255) { my $bits = unpack 'B*', chr $byte; my @offsets; push @offsets, $-[1] while $bits =~ m{(1)}xmsg; push @setbits, [ @offsets ]; } sub find_set_bits { my ($raw_binary) = @_; my @offsets; my $offset = 0; for my $byte (unpack 'C*', $raw_binary) { push @offsets, map $_ + $offset, @{ $setbits[$byte] }; $offset += 8; } return @offsets; } my $str = qq{ 01 02 03 \n 04 00 E0 0a 00 00 00 00 00 00 00 00 00 \n}; (my $hexdigits = $str) =~ s{[^[:xdigit:]]}{}xmsg; my $raw = pack 'H*', $hexdigits; my @ones_offsets = find_set_bits($raw); print qq{'$str'}; print qq{no 1-bits found} unless @ones_offsets; print qq{1-bit found at offset $_} for @ones_offsets; " ' 01 02 03 04 00 E0 0a 00 00 00 00 00 00 00 00 00 ' 1-bit found at offset 7 1-bit found at offset 14 1-bit found at offset 22 1-bit found at offset 23 1-bit found at offset 29 1-bit found at offset 40 1-bit found at offset 41 1-bit found at offset 42 1-bit found at offset 52 1-bit found at offset 54

In reply to Re^2: Working with BIG binary fields by AnomalousMonk
in thread Working with BIG binary fields by juju

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.