Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

A simple PERL script to count the number of zero bits in a given byte.

  1. This PERL script counts the number of zero bits in a given input byte. For examplae if the input is 254 the result is 1.
  2. In language like C it is simple. There are boolean operations, which make the task easy to implement.
  3. To facilitate matters in PERL, I used conversion from decimal to binary.
  4. There are a few ways to do it. I used:
    $b=sprintf("%b", $_[0]);

  5. The rest of the job is achieved by simply counting the zeros using PERL substr.


  6. The script is listed below:
    The first parameter is $_[0] is the input byte. The second one namly, $_[1], holds the output result.

    sub num_of_zero {
      my $b="";
      $j="";
      $l="";
      $b=sprintf("%b", $_[0]);
      $l=length($b);
      $_[1]=8-$l;
      for($j=0; $j < $l; $j++) {
        if(substr($b, $j, 1) == 0) {$_[1]++;}
      }
      print("$_[0] $b $_[1]\n");
    }
  7. This site contains a lot of technical data relating to subjects such as: VHDL, verilog, specman and system C for both design and verification. The best way to look your way round this site, is to use the search my site option (at the bottom of the page).

Contact me now at:

  ...


Home

A simple c-code program to read a memory array from verilog RTL, using VPI.


Text to Integer specman code


Download Area






Search This Site


Feedback This Site




new pages on this site