0
0
VHDLprogramming~20 mins

Concatenation operator (&) in VHDL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Concatenation 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 signal assignment?
Consider the following VHDL code snippet:
signal A : std_logic_vector(3 downto 0) := "1010";
signal B : std_logic_vector(3 downto 0) := "1100";
signal C : std_logic_vector(7 downto 0);

C <= A & B;

What is the value of signal C after this assignment?
VHDL
signal A : std_logic_vector(3 downto 0) := "1010";
signal B : std_logic_vector(3 downto 0) := "1100";
signal C : std_logic_vector(7 downto 0);

C <= A & B;
A"11001010"
B"10101100"
C"1010 1100"
D"11110000"
Attempts:
2 left
💡 Hint
Remember that the & operator joins two vectors by placing the left operand bits first, then the right operand bits.
Predict Output
intermediate
1:30remaining
What is the length of the resulting vector?
Given the following VHDL code:
signal X : std_logic_vector(7 downto 0);
signal Y : std_logic_vector(3 downto 0);
signal Z : std_logic_vector(11 downto 0);

Z <= X & Y;

What is the length of signal Z after the concatenation?
VHDL
signal X : std_logic_vector(7 downto 0);
signal Y : std_logic_vector(3 downto 0);
signal Z : std_logic_vector(11 downto 0);

Z <= X & Y;
A12 bits
B11 bits
C8 bits
D4 bits
Attempts:
2 left
💡 Hint
Add the lengths of both vectors being concatenated.
🔧 Debug
advanced
2:30remaining
Why does this concatenation cause a compilation error?
Examine the following VHDL code:
signal A : std_logic_vector(3 downto 0);
signal B : std_logic_vector(2 downto 0);
signal C : std_logic_vector(7 downto 0);

C <= A & B;

Why does this code cause a compilation error?
VHDL
signal A : std_logic_vector(3 downto 0);
signal B : std_logic_vector(2 downto 0);
signal C : std_logic_vector(7 downto 0);

C <= A & B;
ABecause the length of A & B is 7 bits, which does not match C's 8 bits
BBecause concatenation (&) cannot be used with std_logic_vector
CBecause signal C is not initialized
DBecause signals A and B have different directions (downto)
Attempts:
2 left
💡 Hint
Check the total length of the concatenated vector and compare it to C's length.
📝 Syntax
advanced
1:30remaining
Which option correctly concatenates two std_logic_vectors?
Select the correct VHDL syntax to concatenate two std_logic_vectors A and B into C:
VHDL
signal A, B : std_logic_vector(3 downto 0);
signal C : std_logic_vector(7 downto 0);
AC <= A . B;
BC <= A + B;
CC <= A & B;
DC <= concat(A, B);
Attempts:
2 left
💡 Hint
The concatenation operator in VHDL is &.
🚀 Application
expert
3:00remaining
What is the output of this concatenation and slicing operation?
Given the following VHDL code:
signal A : std_logic_vector(7 downto 0) := "10110011";
signal B : std_logic_vector(3 downto 0) := "1101";
signal C : std_logic_vector(7 downto 0);

C <= (A & B)(11 downto 4);

What is the value of signal C after this assignment?
VHDL
signal A : std_logic_vector(7 downto 0) := "10110011";
signal B : std_logic_vector(3 downto 0) := "1101";
signal C : std_logic_vector(7 downto 0);

C <= (A & B)(11 downto 4);
A"10111101"
B"11001101"
C"11011100"
D"10110011"
Attempts:
2 left
💡 Hint
Concatenate A and B, then select bits 11 downto 4 from the result.