如何将任意大小的整数输入(可以是正数、负数或零)转换为 VHDL 中的二进制数?
How to convert an integer input(could be positive, negative or zero) of any size to its binary in VHDL?
我不想使用 numeric_std 库,因为它在与系统生成器一起使用时给我带来了一些问题。考虑 numeric_std 库的代码如下:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.STD_LOGIC_unsigned.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
entity conversion is
port(l: in integer; k: out std_logic_vector(127 downto 0));
end conversion;
architecture Behavioral of conversion is
begin
k <= conv_std_logic_vector(l,128);
end Behavioral;
请记住输入整数可以有任何值,此方法的替代方法是什么?
Numeric_std 问题
您可能只需要获得以下库包含。如果由于文件中的某些其他代码而无法使用数字标准,请考虑将您的设计设为 组件,即一个单独的实体。实体是独立的编译单元,您可以像这样包含库:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
转化
然后使用numeric_std,你可以像这样转换一个整数:
k <= std_logic_vector(to_signed(l, 127));
32 位限制
注意 VHDL 中的整数类型只是一个带符号的 32 位整数,所以你永远无法用这种方式覆盖 k 的整个范围。
我不想使用 numeric_std 库,因为它在与系统生成器一起使用时给我带来了一些问题。考虑 numeric_std 库的代码如下:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.STD_LOGIC_unsigned.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
entity conversion is
port(l: in integer; k: out std_logic_vector(127 downto 0));
end conversion;
architecture Behavioral of conversion is
begin
k <= conv_std_logic_vector(l,128);
end Behavioral;
请记住输入整数可以有任何值,此方法的替代方法是什么?
Numeric_std 问题
您可能只需要获得以下库包含。如果由于文件中的某些其他代码而无法使用数字标准,请考虑将您的设计设为 组件,即一个单独的实体。实体是独立的编译单元,您可以像这样包含库:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
转化
然后使用numeric_std,你可以像这样转换一个整数:
k <= std_logic_vector(to_signed(l, 127));
32 位限制
注意 VHDL 中的整数类型只是一个带符号的 32 位整数,所以你永远无法用这种方式覆盖 k 的整个范围。