Okay, so here is the code. I inserted a couple of print statements so we can see what it does. I am still not sure I understand the logic behind this script.
#!/usr/bin/perl use strict; use warnings; # To generate the stream of all 1s sub GenerateStream { my $width = shift; my $i; my $j; my $k; my $temp_num = 0; my $numofstrobes = 4; my @strobes; my $all1stream="1" x $width; my $x_num = oct("0b" . $all1stream); # to convert string into int print "\nx_num=$x_num"; # To Calculate the number of streams for($i=4;$i<=$width;$i=$i+4){ $numofstrobes+=int($width/$i); } print "\nwidth=$width; numofstrobes=$numofstrobes; i=$i\n"; #To calculate the bit stream $j=4; for($i=0; $i<$numofstrobes-1; $i++){ my $k=$j-4; my $temp_num=$x_num; while($k<$j) { $temp_num=$temp_num-(2**$k); $k++; } $strobes[$i]=$temp_num; $j+=4; $strobes[$numofstrobes-1]=$x_num; } return @strobes; } my @X; for (my $i = 0; $i < 12; $i++) { @X = GenerateStream($i); foreach my $L (@X) { printf "\n%0.32b", $L; } }

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 harangzsolt33
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.