title: 14 bit binary to 4 digit(16bit) bcd
body: <p>I'm trying to make 14 bit binary to 4 digit bcd. But it does not work well. Give me some ideas</p>
  
  <p>here is my code </p>
  
  <pre><code>module binary2BCD(
      input [13:0] binary,
      output reg [15:0] o
      ); 
  reg [29:0]shift=0; 
  integer i; 
  always@(*) begin
      shift = 30'b0;
       shift[13:0] = binary;
       for (i=0; i&lt;14; i=i+1) begin
              if (shift[17:14] &gt; 4'b0100)
                   shift[17:14] = shift[17:14] + 4'b0011;
              if (shift[21:18] &gt; 4'b0100)
                   shift[21:18] = shift[17:14] + 4'b0011;
              if (shift[25:22] &gt; 4'b0100)
                   shift[25:22] = shift[17:14] + 4'b0011;        
              if (shift[29:26] &gt; 4'b0100)
                   shift[29:26] = shift[17:14] + 4'b0011;
          shift = shift &lt;&lt; 1;
   end
    o= {shift[29:26], shift[25:22], shift[21:18], shift[17:14]};
  end
  endmodule
  </code></pre>