How to write an integer to stdout as hexadecimal in VHDL?

后端 未结 3 2120
温柔的废话
温柔的废话 2021-02-15 16:52

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
    p         


        
3条回答
  •  长情又很酷
    2021-02-15 17:40

    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
    

    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.

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

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

提交回复
热议问题