VHDL – How to Use ‘if’ for Variable Comparison

comparisonifvhdl

Using Xilinx, I need to compare a 'variable' called 'row', defined as:

variable row   : std_logic_vector(2 * n - 1 downto 0);

This line was given to me, now I need an if statement that will execute if row is = 1.

I have tried:

if (row = "1") then

but the IDE warns me that this condition will always result in false? which should not happen.

If I try if (row = '1') then or if (row = 1) then then I get the error:

found '0' definitions of operator "="

Googling this, the only suggestion is to include libraries that I have already included:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

Best Answer

Your variable is a std_logic_vector and you compare it to an integer. You have to cast the std_logic_vector like this:

if(to_integer(signed(row)) = 1) or if(to_integer(unsigned(row)) = 1)