0
0
VHDLprogramming~20 mins

Shift operators in VHDL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
VHDL Shift Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this VHDL shift operation?
Given the following VHDL code snippet, what is the value of result after execution?
VHDL
signal input_val : std_logic_vector(7 downto 0) := "00011011";
signal result : std_logic_vector(7 downto 0);

begin
  result <= input_val sll 2;
A"01101100"
B"00011011"
C"00110110"
D"11011000"
Attempts:
2 left
💡 Hint
Remember that 'sll' shifts bits to the left and fills with zeros on the right.
Predict Output
intermediate
2:00remaining
What is the result of this right shift in VHDL?
Consider this VHDL code. What is the value of output_val after the shift?
VHDL
signal input_val : std_logic_vector(7 downto 0) := "10110010";
signal output_val : std_logic_vector(7 downto 0);

begin
  output_val <= input_val srl 3;
A"11001000"
B"10110010"
C"00010110"
D"00010111"
Attempts:
2 left
💡 Hint
The 'srl' operator shifts bits right and fills with zeros on the left.
🔧 Debug
advanced
2:00remaining
Identify the error in this VHDL shift operation
What error will this VHDL code produce when compiled?
VHDL
signal data : std_logic_vector(7 downto 0) := "11110000";
signal shifted : std_logic_vector(7 downto 0);

begin
  shifted <= data sra 2;
AType mismatch error: shifted and data have different sizes
BSyntax error: 'sra' cannot be used with std_logic_vector
CNo error, result is "11111100"
DRuntime error: shift amount too large
Attempts:
2 left
💡 Hint
Check the type compatibility of the 'sra' operator in VHDL.
🧠 Conceptual
advanced
2:00remaining
What is the difference between 'srl' and 'sra' in VHDL?
Choose the correct explanation of the difference between the 'srl' and 'sra' shift operators in VHDL.
A'srl' and 'sra' both shift left but differ in fill bits.
B'srl' shifts bits left; 'sra' shifts bits right filling with zeros.
C'srl' shifts right preserving the sign bit; 'sra' shifts right filling with zeros.
D'srl' shifts bits right filling with zeros; 'sra' shifts right preserving the sign bit for signed types.
Attempts:
2 left
💡 Hint
Think about how signed numbers behave when shifted right.
Predict Output
expert
3:00remaining
What is the output of this combined shift operation in VHDL?
Given the following VHDL code, what is the final value of final_val?
VHDL
signal val : std_logic_vector(7 downto 0) := "10011100";
signal final_val : std_logic_vector(7 downto 0);

begin
  final_val <= (val sll 1) srl 2;
A"00001110"
B"00100111"
C"01001110"
D"10011100"
Attempts:
2 left
💡 Hint
Apply the shifts step by step: first left shift by 1, then right shift by 2.