Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need a verilog code to convert 16 bit from hexadecimals to BCD i used this cod

ID: 3583719 • Letter: I

Question

i need a verilog code to convert 16 bit from hexadecimals to BCD

i used this code but it gives me wrong answer

module bcd_conv_16bit (input [15:0] binary,
   output reg [15:0]y
   );

   reg [31:0] z;
  
   integer i;
   always@(binary)
       begin
           for(i=1 ; i<=31 ; i=i+1)
               z[i] = 0;
               z[18:3] = binary;
               for(i=1 ; i<=12 ; i=i+1)
               begin
                   if(z[19:16] > 4)
                       z[19:16] = z[19:16] + 3;
                       if(z[23:20] > 4)
                           z[23:20] = z[23:20] + 3;
                           if(z[27:24] > 4)
                               z[27:24] = z[27:24] + 3;
                               if(z[31:25] > 4)
                                   z[31:25] = z[31:25] + 3;
                                   z[31:1] = z[30:0];
                               end
                               y = z[31:16];
                               end
                                  
endmodule

Explanation / Answer

module bcd_conv_16bit (input [15:0] binary,
   output reg [15:0]y
   );

   reg [31:0] z;
  
   integer i;
   always@(binary)
       begin
           for(i=0 ; i<=31 ; i=i+1)
               z[i] = 0;
               z[18:3] = binary;
               for(i=0 ; i<=12 ; i=i+1)
               begin
                   if(z[19:16] > 4)
                       z[19:16] = z[19:16] + 3;
                       if(z[23:20] > 4)
                           z[23:20] = z[23:20] + 3;
                           if(z[27:24] > 4)
                               z[27:24] = z[27:24] + 3;
                               if(z[31:28] > 4)
                                   z[31:28] = z[31:28] + 3;
                                   z[31:1] = z[30:0];
                               end
                               y = z[31:16];
                               end
                                  
endmodule

Check the values in Bold and change in ur code.