如何在 VHDL 中以十六进制形式将整数写入标准输出? [英] How to write an integer to stdout as hexadecimal in VHDL?

查看:34
本文介绍了如何在 VHDL 中以十六进制形式将整数写入标准输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将 integer 作为十进制打印到标准输出:

I can print an integer as decimal to stdout with:

library std;
use std.textio.all;

entity min is
end min;

architecture behav of min is
begin
    process is
        variable my_line : line;
    begin
        write(my_line, 16);
        writeline(output, my_line);
        wait;
    end process;
end behav;

输出:

16

但是如何输出:

10
0x10

推荐答案

假设一个整数 i 和 VHDL-2008,你可以使用:

Assuming an integer i, and VHDL-2008, you could use:

write(output, integer'image(i) & LF);  -- Plain integer value
write(output, "0x" & to_hstring(to_signed(i, 32)) & LF);  -- Hexadecimal representation

您需要让 use std.textio.all; 才能工作.更改 32 以减少十六进制值的长度.我选择了 32 以便它可以在大多数模拟器中表示任何整数值.

You need to have use std.textio.all; for this to work. Change the 32 to reduce the length of the hex value. I chose 32 so that it can represent any integer value in most simulators.

这些也适用于 report 语句,例如

These will also work for report statements, e.g.

report "i = 0x" & to_hstring(to_signed(i, 32));

这篇关于如何在 VHDL 中以十六进制形式将整数写入标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆