spriyada29 has asked for the wisdom of the Perl Monks concerning the following question:
I want to generate an array of bit streams depending on the width with each nibble(4 bits)taking either all 1s or 0s. Width is a multiple of 4 E.g. 1. if my Width= 8. I would like to generate 3 bit streams as 11110000 00001111 11111111 if Width=12 , My array should have elements like 111111111111 111111110000 111100001111 000011111111 111100000000 I have tried to generate it using the following perl code
It's working fine to generate stream with changing just nibbles around but doesn't work for case where I need to make let's say 2 nibbles 0s(1111 0000 0000) can someone help me with it or can suggest a better way to do it ?my $numofstrobes; my @strobes; # To generate the stream of all 1s my $all1stream="1" x $width; my $x_num = oct("0b" . $all1stream); # to convert string into int #To Calculate the number of streams for($i=4;$i<=$width;$i=$i+4){ $numofstrobes+=int($width/$i); } #To calculate the bit stream `my $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`;
|
|---|