有关conv_std_logic_vector和conv_integer
std_logic_arith
This is the library that defines some types and basic arithmetic operations for representing integers in standard ways. This is a Synopsys extention. The source code is instd_logic_arith.vhd and is freely redistributable.
The unsigned type
The signed type
The arithmetic functions: +, -, *
The comparison functions: <, <=, >, >=, =, /=
The shift functions: shl, shr
The conv_integer function
The conv_unsigned function
The conv_signed function
The conv_std_logic_vector function
-------------------------------------------------------------------------------------------------------------------------------
The conv_integer function
function conv_integer(arg: integer) return integer;
function conv_integer(arg: unsigned) return integer;
function conv_integer(arg: signed) return integer;
function conv_integer(arg: std_ulogic) return small_int;
These functions convert the arg argument to an integer. If the argument contains any undefined elements, a runtime warning is produced and 0 is returned.
The function provided by the std_logic_arith library can't convert a std_logic_vector to an integer because it is impossible to determine if it represents an unsigned or signed value.Functions that do this are included in the std_logic_unsigned and std_logic_signed libraries.
Examples
signal b : std_logic;
signal u1 : unsigned (3 downto 0);
signal s1 : signed (3 downto 0);
signal i1, i2, i3 : integer;
...
u1 <= "1001";
s1 <= "1001";
b <= 'X';
wait for 10 ns;
i1 <= conv_integer(u1); -- 9
i2 <= conv_integer(s1); -- -7
i3 <= conv_integer(b); -- warning produced in simulator
以上蓝字说明了一切
1.前一个包含在std_logic_arith.all程序包中
2.后一个在std_logic_unsigned 和std_logic_signed 中都有包含
计算机中的运算都是用2进制补码的,本人总结,在做算法时候,包含std_logic_signed 这个包比较好,这样conv_integer 就把需要转换的数据变成了带符号的整数,然而std_logic_unsigned就把需要转换的数据变成了无符号的整数。
3. conv_std_logic_vector 函数的转换结果是将被转换的数据先转换成2进制补码形式,然后取其低“位长”,作为输出。
如:a<=conv_std_logic_vector(-79,6)----(-79)2c=(10110001)
b<=conv_std_logic_vector(-2,6)-----(-2)2c=(11111110)
c<=conv_std_logic_vector(100,6)-----(100)2c=(01100100)
输出结果:a=110001,b=111110,c=100100
4.本人做了这样的转换conv_std_logic_vector (conv_integer (data),16),data是16范围内的有符号数,但是接口是32位的标准矢量形式(std_logic_vector(31 downto 0)刚开始包括的是std_logic_unsigned 包,发现数据变得面目全非了,想来想去,认为conv_integer (data)的原因,就该了下包,结果就正确了。
有关conv_std_logic_vector和conv_integer的更多相关文章
- VHDL学习之TEXTIO在仿真中的应用
TEXTIO 在VHDL 仿真与磁盘文件之间架起了桥梁,使用文本文件扩展VHDL 的仿真功能.本文介绍TEXTIO 程序包,以一个加法器实例说明TEXTIO 的使用方法,最后使用ModelSim 对设 ...
- VHDL数据类型转换
函 数 名 功 能 STD_LOGIC_1164包集合 TO_STDLOG ...
- VHDL 类型转换
STD_LOGIC_1164包集合 函 数 名 功 能 TO_STDLOGICVECTOR(A) 由BIT_VECTOR转换为STD_LOGIC_VECTOR TO_BITVECTOR(A) 由STD ...
- VHDL基础1
Description Structure 一个可综合的VHDL描述中一般由3部分组成:LIBRARY declarations.ENTITY.ARCHITECTURE Library(库)用来设计重 ...
- VHDL和verilog应该先学哪个?
网上有太多的VHDL和verilog比较的文章,基本上说的都是VHDL和verilog之间可以实现同一级别的描述,包括仿真级.寄存器传输级.电路级,所以可以认为两者是等同级别的语言.很多时候会了其中一 ...
- VHDL 数字时钟设计
序言 这个是我在做FPGA界的HelloWorld--数字钟设计时随手写下的,再现了数字钟设计的过程 目标分析 时钟具有时分秒的显示,需6个数码管.为了减小功耗采用扫描法显示 按键设置时间,需要对按键 ...
- 嵌入式CISC模型机设计
一. 课程设计的题目和内容 题目:设计一台嵌入式CISC模型计算机 采用定长CPU周期.联合控制方式,并运行能完成一定功能的机器语言源程序进行验证,机器语言源程序功能如下: 任意输入5个整数, ...
随机推荐
- python——爬虫&问题解决&思考(1)
最近刚接触python,找点小任务来练练手,希望自己在实践中不断的锻炼自己解决问题的能力.这个小爬虫来自慕课网的一门课程,我在这里记录的是自己学习的过程中遇到的问题和解决方法以及爬虫之外的思考. 这次 ...
- js与jQuery对象相互转换
// jQuery-->JavaScript 两种方法: $(selector).get(index) ; $(selector)[index]; // JavaScript-->jQue ...
- #414 Div2 C
#414 Div2 C 题意 两个人每个人都有一串字母序列,他们要替换一个长度为 n 包含问号的新序列,他们每次可以使用自己序列中的字母代替新序列的问号(使用自己序列中的字母后那个字母就会消失),第一 ...
- 【JAVAEE学习笔记】hibernate03:多表操作详解、级联、关系维护和练习:添加联系人
一.一对多|多对一 1.关系表达 表中的表达 实体中的表达 orm元数据中表达 一对多 <!-- 集合,一对多关系,在配置文件中配置 --> <!-- name属性:集合属性名 co ...
- java音视频编解码问题:16/24/32位位音频byte[]转换为小端序short[],int[],以byte[]转short[]为例
前言:Java默认采用大端序存储方式,实际编码的音频数据是小端序,如果处理单8bit的音频当然不需要做转换,但是如果是16bit或者以上的就需要处理成小端序字节顺序. 注:大.小端序指的是字节的存储顺 ...
- zookeeper-开始
ZooKeeper:为分布式应用提供的分布式协调服务 ZooKeeper提供一系列原语用于分布式应用构建更高层次的服务,如同步.配置维护.分组以及命名空间. 设计目标: ZooKeeper足够简单且可 ...
- 动态分配数组(new)和用随机数赋值(rand)
#include <iostream>#include <ctime>#include <cstdlib>using namespace std; int main ...
- scrapy架构初探
scrapy架构初探 引言 Python即时网络爬虫启动的目标是一起把互联网变成大数据库.单纯的开放源代码并不是开源的全部,开源的核心是"开放的思想",聚合最好的想法.技术.人员, ...
- Ubuntu16.04更换漂亮绚丽flatabulous主题
作者:tongqingliu 转载请注明出处: Ubuntu16.04更换漂亮绚丽flatabulous主题 更新 sudo apt-get update sudo apt-get upgrade 安 ...
- forfiles命令批处理删除过期文件
命令格式: forfiles.exe /p "D:\备份" /s /m *.zip /d -7 /c "cmd /c del @path" /p:指定目录 /s ...