Prev Problem
Next Problem

14. Logical Shifter

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

The left shift operator (<<) and right shift operator (>>) can be interpreted as multiplication and division by powers of two. Specifically, A<<shamt is equivalent to A*(2^shamt) and A>>shamt is equivalent to A/(2^shamt) for unsigned numbers.
 

 

Code

module shift8(
    input wire [7:0] A,
    input wire [2:0] shamt,     //shIFT_amOUNt
    output wire [7:0] SHL,
    output wire [7:0] SHR
);

    assign SHL = A << shamt;
    assign SHR = A >> shamt;
    
endmodule

 

Was this helpful?
Upvote
Downvote