一、STD_LOGIC_VECTOR 转 INTEGER
先将STD_LOGIC_VECTOR根据需求使用signed()转为 SIGNED 或者 使用 unsigned() 转为 UNSIGNED (signed() 和 unsigned() 在 numeric_std 中),
然后使用 conv_integer() 或者 to_integer() 转为整数。
conv_integer() 和 to_integer() 二者分别在不同的Library中。
Function "conv_integer" defined in Synopsys Library : std_logic_arith, defined as:
USE IEEE.STD_LOGIC_ARITH.ALL;
function CONV_INTEGER(ARG: UNSIGNED) return INTEGER;
function CONV_INTEGER(ARG: SIGNED) return INTEGER;
Function "To_integer" defined in IEEE library: numeric_std, defined as:
USE IEEE.NUMERIC_STD.ALL;
function TO_INTEGER (ARG: UNSIGNED) return INTEGER;
function TO_INTEGER (ARG: SIGNED) return INTEGER;
例:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
entity conv_test is
Port ( a : in STD_LOGIC_VECTOR (7 downto 0);
b : out integer);
end conv_test;
architecture Behavioral of conv_test is
begin
b <= to_integer(signed(a));
end Behavioral;
https://www.xilinx.com/support/answers/45213.html
一、INTEGER 转 STD_LOGIC_VECTOR
先将INTEGER根据需求使用 to_signed(interger,signed'length) 转为 SIGNED 或者使用 to_unsigned(integer,unsigned'length) 转为UNSIGNED,
然后使用STD_LOGIC_VECTOR(signed/unsigned)转为整数。
例:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
signal input_1 : integer;
signal output_1a : std_logic_vector(3 downto 0);
signal output_1b : std_logic_vector(3 downto 0);
-- This line demonstrates how to convert positive integers
output_1a <= std_logic_vector(to_unsigned(input_1, output_1a'length));
-- This line demonstrates how to convert positive or negative integers
output_1b <= std_logic_vector(to_signed(input_1, output_1b'length));
https://www.nandland.com/vhdl/examples/example-signed-unsigned.html