vhdl - VHDL shift_right 数字
问题描述
我想将一个数字除以 512,这意味着我需要将其除以 9。例如,在我的代码中,我想将二进制形式的数字 26 乘以 100,然后除以 512。但不是除以 512我需要做的就是将数字 26*100 向右移动 9 倍。但是当我执行shift_right
命令时,出现以下错误:
错误 (10511):Multiplier_VHDL .vhd(34) 处的 VHDL 限定表达式错误:限定表达式中指定的 SHIFT_RIGHT 类型必须与上下文表达式隐含的 std_logic_vector 类型匹配
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Multiplier_VHDL is
GENERIC (
display_resolution : INTEGER := 23; -- counter to get to the lowest frequency
display_counter: INTEGER := 8); -- counter to get to 97KHz frequency
port (
Nibble1 : in std_logic_vector(display_counter downto 0) := "000011010"; -- 26 in binary form
Nibble2 : in std_logic_vector(display_counter downto 0);
Result: out std_logic_vector(17 downto 0));
end entity Multiplier_VHDL;
architecture Behavioral of Multiplier_VHDL is
signal number : unsigned(display_counter downto 0) := "001100100"; -- 100 in binary form
begin
Result <= std_logic_vector(unsigned(Nibble1) * unsigned(number));
Result <= (shift_right(unsigned(number), display_counter + 1));
end architecture Behavioral;
解决方案
shift_right 返回无符号或有符号,具体取决于您提供的内容。因此,您尝试将无符号写入 std_logic_vector(结果为 std_logic_vector 类型)。
此外,number
已经是类型unsigned
,因此无需unsigned
再次将其转换为。
但是对于使用 numeric_std 而不是 std_logic_arith,我给你 +1 分。
推荐阅读
- linux - Bash binary reports a different version at different times
- c# - 在 HTTP 请求中热使用证书票证
- ios - 在 swift 中添加一个 BlockOperation 对另一个 BlockOperation 的依赖不能正常工作
- c# - XAML 根据 Rectangle 的大小更改 TextBlock Margin 属性
- google-apps-script - 如何使用 Apps 脚本对齐 Google Docs 中的附加图像
- mysql - SELECT忽略分区?
- excel - 如何转置复制的数据?
- office-js - 如何在 Windows 10 1903 上的 Outlook 中清除缓存的加载项起始页?
- python - 从文本文件为确定性有限自动机创建 Python 字典
- python - 用 CSV 的内容填充 ipywidget 下拉列表?