module decoder_using_assign (input wire [3:0] binary_in ,output wire [15:0] decoder_out,input wire enable);
assign decoder_out = (enable) ? (1 << binary_in) : 16’b0 ;
endmodule
can anyone explain the how the shift operator is work in the above module
Whenever enable is HIGH, the output will be one bit (1’b1) shifted left by binary_in times. The decoder_out will be one hot in this case.
For example,
enable = 1'b1
binary_in = 4'b0100 = 4'h3
decoder_out = 1<<4'h3 = 16'h0000_0000_0000_1000 = 16'h0008
enable = 1'b1
binary_in = 4'b0110 = 4'h6
decoder_out = 1<<4'h6 = 16'h0000_0000_0100_0000 = 16'h0040
enable = 1'b1
binary_in = 4'b1111 = 4'hF
decoder_out = 1<<4'hF = 16'h1000_0000_0000_0000 = 16'h8000
The logical left shift shall fill the vacated bit positions with zeros.