I can tell you how to produce all the permutations of 0's and 1's of given bit-width : simply count from 0 to 2^bit_width and print with binary format. But I can not fathom the logic for discarding or accepting some of these. For example, for a width=8 you discarded 1 case. For width=12 you discarded 3 such cases.

#!/usr/bin/perl # author: bliako # date: 16/11/2018 # https://perlmonks.org/?node_id=1225889 # for given width, it counts from 0 to 2**W # and prints the count in binary. # It misses logic to discard some nibbles use strict; use warnings; my $W = 4; # width in nibbles my $count = 0; my $stop = 2**$W; # format an integer as binary my $format = "%0.${W}b"; while( $count < $stop ){ my $x = sprintf($format, $count); # x now contains a binary number of the count # between 0 and the stop 2^width_in_nibbles # now make each digit a nibble, e.g 0 -> 0000 $x =~ s/0/a/g; $x =~ s/1/b/g; $x =~ s/a/0000 /g; $x =~ s/b/1111 /g; print "x=$x ($count)\n"; $count++; }
0 0000 0000 0000 0000 1 0000 0000 0000 1111 2 0000 0000 1111 0000 3 0000 0000 1111 1111 4 0000 1111 0000 0000 5 0000 1111 0000 1111 6 0000 1111 1111 0000 7 0000 1111 1111 1111 8 1111 0000 0000 0000 9 1111 0000 0000 1111 10 1111 0000 1111 0000 11 1111 0000 1111 1111 12 1111 1111 0000 0000 13 1111 1111 0000 1111 14 1111 1111 1111 0000 15 1111 1111 1111 1111

In reply to Re: Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl by bliako
in thread Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl by spriyada29

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.