BitFlow

4-bit Barrel Shifter

beginner · combinational · 65 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

4-bit Barrel Shifter Input: 4-bit `data[3:0]`, 2-bit shift amount `shamt[1:0]`, 1-bit direction `dir` (0=left, 1=right). Output: 4-bit `result[3:0]`. Shift fills with zeros. Use `case` or concatenation — no `<<`/`>>` operators. **Examples (left shift, dir=0)** - `data=4'hF, shamt=1 → result=4'hE` (1111 → 1110) - `data=4'hF, shamt=2 → result=4'hC` (1111 → 1100) **Examples (right shift, dir=1)** - `data=4'hF, shamt=1 → result=4'h7` (1111 → 0111) - `data=4'hF, shamt=2 → result=4'h3` (1111 → 0011)

Constraints

  • No << or >> operators.
  • Implement with case/if-else or concatenation.
  • Zero-fill on shift.

Examples

Input: data=4'hF, shamt=1, dir=0

Output: result=4'hE

Input: data=4'hF, shamt=1, dir=1

Output: result=4'h7

Common questions

What does the 4-bit Barrel Shifter problem ask you to build?
4-bit Barrel Shifter Input: 4-bit `data[3:0]`, 2-bit shift amount `shamt[1:0]`, 1-bit direction `dir` (0=left, 1=right). Output: 4-bit `result[3:0]`. Shift fills with zeros. Use `case` or concatenation — no `<<`/`>>` operators.
What constraints does 4-bit Barrel Shifter have?
No << or >> operators.; Implement with case/if-else or concatenation.; Zero-fill on shift.
What is an example input and output for 4-bit Barrel Shifter?
Input data=4'hF, shamt=1, dir=0 gives output result=4'hE.
Which Verilog concepts does 4-bit Barrel Shifter practise?
combinational, shifter, interview, mux.