我想知道如何在VHDL测试平台中将std_logic_vector写为有符号整数?
使用numeric_std:
signal test_in : std_logic_vector(2 downto 0); signal test_out : integer range -4 to 3; test_out <= to_integer(signed(test_in));
您需要转换为整数(使用 use ieee.numeric_std.all; ,这意味着您需要知道 std_logic_vector 是表示有符号或无符号数.Ideally, you'd use the relevant type rather than the bag-of-bits that std-logic_vector is.
use ieee.numeric_std.all;
std_logic_vector
转换为整数非常简单:
int_variable := to_integer(some_vector);
如果你必须坚持 std_logic_vector ,你必须告诉编译器它是无符号还是像这样签名:
int_variable := to_integer(unsigned(some_vector));
或这个:
int_variable := to_integer(signed(some_vector));
然后你可以像往常一样将整数写入文件 .
2 回答
使用numeric_std:
您需要转换为整数(使用
use ieee.numeric_std.all;
,这意味着您需要知道std_logic_vector
是表示有符号或无符号数.Ideally, you'd use the relevant type rather than the bag-of-bits that std-logic_vector is.转换为整数非常简单:
如果你必须坚持
std_logic_vector
,你必须告诉编译器它是无符号还是像这样签名:或这个:
然后你可以像往常一样将整数写入文件 .