How to convert std_logic_vector to hexadecimal

1. How to convert std_logic_vector to hexadecimal

How to convert std_logic_vector to hexadecimal ?

Thanks. •

2. How to convert std_logic_vector to hexadecimal

Hexadecimal is not a type like std_logic_vector. Hexadecimal is a representation. So, you can always represent the std_logic_vector signal in terms of Hex format.

What do you want to do exactly ? 3. Re: How to convert std_logic_vector to hexadecimal

I want to convert std_logic_vector to character.

Should I convert std_logic_vector to hexadecimal first?

the following is my code:

Code:
procedure hex2chr( variable hex  : in std_logic_vector( 3 downto 0);
variable char : out character) is
begin
case hex is
when "0000" =>    char:='0';
when "0001" =>    char:='1';
when "0010" =>    char:='2';
when "0011" =>    char:='3';
when "0100" =>    char:='4';
when "0101" =>    char:='5';
when "0110" =>    char:='6';
when "0111" =>    char:='7';
when "1000" =>    char:='8';
when "1001" =>    char:='9';
when "1010" =>    char:='a';
when "1011" =>    char:='b';
when "1100" =>    char:='c';
when "1101" =>    char:='d';
when "1110" =>    char:='e';
when "1111" =>    char:='f';
when others =>
ASSERT (false) REPORT "no hex character read" SEVERITY failure;
end case;
end hex2chr;
Thanks. •

4. How to convert std_logic_vector to hexadecimal

character is a VHDL standard type, but it has no particular purpose in synthesis, it's mainly used in text_io for simulation purposes. So what do you want to do with the char output of the procedure? 5. Re: How to convert std_logic_vector to hexadecimal

I am doing a closed loop simulation.

I want to record the feed-back std_logic_vector.

Thanks. 6. How to convert std_logic_vector to hexadecimal

So you want to perform hexadecimal textio output. This should work.

1 members found this post helpful. •

7. Re: How to convert std_logic_vector to hexadecimal

are you sure?

looks like it has erros, keep showing "ASSERT (false) REPORT "no hex character read" SEVERITY failure;"

why? 8. Re: How to convert std_logic_vector to hexadecimal

Check out this one!

Code:
function to_hstring (value     : STD_ULOGIC_VECTOR) return STRING is
constant ne     : INTEGER := (value'length+3)/4;
variable pad    : STD_ULOGIC_VECTOR(0 to (ne*4 - value'length) - 1);
variable ivalue : STD_ULOGIC_VECTOR(0 to ne*4 - 1);
variable result : STRING(1 to ne);
variable quad   : STD_ULOGIC_VECTOR(0 to 3);
begin
if value'length < 1 then
return NUS;
else
if value (value'left) = 'Z' then
pad := (others => 'Z');
else
pad := (others => '0');
end if;
ivalue := pad & value;
for i in 0 to ne-1 loop
quad := To_X01Z(ivalue(4*i to 4*i+3));
when x"0"   => result(i+1) := '0';
when x"1"   => result(i+1) := '1';
when x"2"   => result(i+1) := '2';
when x"3"   => result(i+1) := '3';
when x"4"   => result(i+1) := '4';
when x"5"   => result(i+1) := '5';
when x"6"   => result(i+1) := '6';
when x"7"   => result(i+1) := '7';
when x"8"   => result(i+1) := '8';
when x"9"   => result(i+1) := '9';
when x"A"   => result(i+1) := 'A';
when x"B"   => result(i+1) := 'B';
when x"C"   => result(i+1) := 'C';
when x"D"   => result(i+1) := 'D';
when x"E"   => result(i+1) := 'E';
when x"F"   => result(i+1) := 'F';
when "ZZZZ" => result(i+1) := 'Z';
when others => result(i+1) := 'X';
end case;
end loop;
return result;
end if;
end function to_hstring;

Hope this helps! --[[ ]]--