0
0
VHDLprogramming~5 mins

Concatenation operator (&) in VHDL

Choose your learning style9 modes available
Introduction

The concatenation operator (&) in VHDL joins two or more bit vectors or strings together to make a longer one. It helps combine smaller pieces into one bigger piece.

When you want to join two signals or variables to form a wider signal.
When creating a larger data word from smaller parts, like combining bytes into a word.
When building a new vector from separate bits or smaller vectors.
When formatting output by joining strings or characters.
When you need to add a prefix or suffix to a bit vector or string.
Syntax
VHDL
result <= vector1 & vector2;

The & operator joins two vectors or strings end-to-end.

Both operands must be of compatible types (e.g., both bit_vectors or both strings).

Examples
Joins two 4-bit vectors A and B into one 8-bit vector C.
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;
Concatenates a single bit X with a 4-bit vector Y to make a 5-bit vector Z.
VHDL
signal X : std_logic := '1';
signal Y : std_logic_vector(3 downto 0) := "0011";
signal Z : std_logic_vector(4 downto 0);

Z <= X & Y;
Joins two strings greeting and name into one longer string message.
VHDL
variable greeting : string(1 to 5) := "Hello";
variable name : string(1 to 4) := "John";
variable message : string(1 to 9);

message := greeting & name;
Sample Program

This program joins two 4-bit vectors part1 and part2 into one 8-bit vector combined. It then prints the combined vector as a string.

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity concat_example is
end entity;

architecture behavior of concat_example is
  signal part1 : std_logic_vector(3 downto 0) := "1010";
  signal part2 : std_logic_vector(3 downto 0) := "0101";
  signal combined : std_logic_vector(7 downto 0);
begin
  combined <= part1 & part2;

  process
  begin
    wait for 10 ns;
    report "Combined vector: " & to_string(combined);
    wait;
  end process;
end architecture;
OutputSuccess
Important Notes

Make sure the vectors or strings you join have compatible types and sizes.

The order matters: A & B puts A first, then B.

You can chain multiple concatenations like A & B & C.

Summary

The & operator joins two vectors or strings end-to-end.

Use it to build bigger signals or strings from smaller parts.

Operands must be compatible types and the order affects the result.