title: How to output a bmp file using verilog?
body: <p>I was asked to using the data in a bmp file as the simulation input for a verilog module and write the simulation output to a new bmp file, so that they can compare the two different bmp file to check the correction of verilog module.
  I succeeded in read, but met some problems in writing.
  <code>
  module testsub1;
  integer fout;
  initial 
      begin
          fout=$fopen("C:/Users/gyz/Pictures/testout1.bmp","wb");
          $fwrite(fout,"%u",8'h42);
          $fclose(fout);
      end
  endmodule
  </code>
  The output is supposed to be 8'h42. But the real output is 
  <a href="https://i.stack.imgur.com/PdxFB.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Needless zero occur. I guess it is because verilog write row binary at least 16n bit at a time, n >=1. So I change the sixth line into <code>$fwrite(fout,"%u",24'h424d5f);</code>,the result becomes 
  <a href="https://i.stack.imgur.com/raA3X.png" rel="nofollow noreferrer">enter image description here</a>
  There is still a redundant zero. How can I make the program just output 8 bits each time.</p>