首页 文章

VHDL将std_logic_vector写为文件中的有符号整数

提问于
浏览
1

我想知道如何在VHDL测试平台中将std_logic_vector写为有符号整数?

2 回答

  • 0

    使用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));
    
  • 2

    您需要转换为整数(使用 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.

    转换为整数非常简单:

    int_variable := to_integer(some_vector);
    

    如果你必须坚持 std_logic_vector ,你必须告诉编译器它是无符号还是像这样签名:

    int_variable := to_integer(unsigned(some_vector));
    

    或这个:

    int_variable := to_integer(signed(some_vector));
    

    然后你可以像往常一样将整数写入文件 .

相关问题