25

Inside a process I have something like this:

CASE res IS
  WHEN "00" => Y <= A;
  WHEN "01" => Y <= A;
  WHEN "10" => Y <= B;
  WHEN "11" => Y <= C;
  WHEN OTHERS => Y <= 'X';
END CASE;

Note that case "00" and "01" get the same value. Is there a correct syntax for something like

WHEN "00", "01" => ?

Extra note: There's far more to this than Y being changed, I just used that for simplicity. So the case/when is necessary.

Jay Wick
  • 12,325
  • 10
  • 54
  • 78

2 Answers2

39

You can separate multiple choices with the "pipe" or bar symbol. The proper syntax for your example is:

CASE res IS
  WHEN "00" | "01" => Y <= A;
  WHEN "10" => Y <= B;
  WHEN "11" => Y <= C;
  WHEN OTHERS => Y <= 'X';
END CASE;
Charles Steinkuehler
  • 3,335
  • 18
  • 12
10

You can also give a range of choices for a case:

USE IEEE.NUMERIC_STD.ALL;

CASE TO_INTEGER(res) IS
  WHEN 0 to 1 => Y <= A;
  WHEN 2 => Y <= B;
  WHEN 3 => Y <= C;
  WHEN OTHERS => Y <= 'X';
END CASE;
Harry
  • 884
  • 1
  • 8
  • 19
VahidG
  • 165
  • 1
  • 7