conv_integer
function
function conv_integer(arg: integer) return integer;
function conv_integer(arg: unsigned) return integer;
function conv_integer(arg: signed) return integer;
function conv_integer(arg: std_ulogic) return small_int;
These functions convert the arg
argument to an integer. If the argument contains any undefined elements, a runtime warning is produced and 0 is returned.
The function provided by the std_logic_arith
library can't convert a std_logic_vector
to an integer because it is impossible to determine if it represents an unsigned or signed value. Functions that do this are included in the std_logic_unsigned
and std_logic_signed
libraries.
signal b : std_logic; signal u1 : unsigned (3 downto 0); signal s1 : signed (3 downto 0); signal i1, i2, i3 : integer; ... u1 <= "1001"; s1 <= "1001"; b <= 'X'; wait for 10 ns; i1 <= conv_integer(u1); -- 9 i2 <= conv_integer(s1); -- -7 i3 <= conv_integer(b); -- warning produced in simulator