0
\$\begingroup\$

This code is from asic-world:

module decoder_using_assign (
 binary_in , // 4 bit binary input
 decoder_out , // 16-bit out 
 enable // Enable for the decoder
);
 input [3:0] binary_in ;
 input enable ; 
 output [15:0] decoder_out ; 
 wire [15:0] decoder_out ; 
 assign decoder_out = (enable) ? (1 << binary_in) : 16'b0 ;
endmodule

I can't seem to wrap my head around (1 < < binary_in). binary_in is 4 bits wide, how is the logical left shift producing an output 16 bits wide when enable is true?

asked Jan 25, 2015 at 2:05
\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

binary_in is 4 bits, so can hold a decimal value anywhere in the range 0-15.

If you left shift 1 by between 0 and 15, you get a number with at most 16 bits.

16'b0000000000000001 << 0 = 16'b0000000000000001

16'b0000000000000001 << 1 = 16'b0000000000000010

16'b0000000000000001 << 2 = 16'b0000000000000100

...

16'b0000000000000001 << 15 = 16'b1000000000000000

answered Jan 25, 2015 at 2:10
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.