Monday, September 28, 2009

STD_LOIC_VECTOR to INTEGER

The IEEE libraries std_logic_arith and numeric_std supports std_logic_vector to integer conversion. std_logic_arith uses the function conv_integer, while numeric_std uses the function to_integer for the conversion. In both the cases std_logic_vector should be converted into signed or unsigned before it is passed to the functions.

Example using std_logic_arith:
USE IEEE.STD_LOGIC_ARITH.all;
-- Variable decleration
variable my_vector : STD_LOGIC_VECTOR (3 downto 0) := "1111" ;
variable my_integer : integer ;
-- Conversion
my_integer := conv_integer (unsigned (my_vector)) ;

Example using numeric_std:
USE IEEE.NUMERIC_STD.all;
-- Variable decleration
variable my_vector : STD_LOGIC_VECTOR (3 downto 0) := "1111" ;
variable my_integer : integer ;
-- Conversion
my_integer := to_integer (unsigned (my_vector)) ;

No comments:

Post a Comment