Search code examples
veriloghdl

Multiplying number by ten in verilog


How do you multiply a binary number by ten in verilog? Is it as simple as

reg [7:0] a,b;
reg[31:0] p;
b= 8'b00001001;
p=a*b;

Upgraded to windows 8 and my xilinx is working atm. Need to know asap for planning stage.


Solution

  • Nearly - 10 in binary is 1010! For multiplying two 8-bit numbers, you'll only need 16 bits for the result, so reg [15:0] p would do. What about:

     always @( a )
         p = a * 8'd10; 
    

    or

    wire [13:0] p;
    assign p = a * 4'd10;