Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert std_logic_vector to hexadecimal

Status
Not open for further replies.

EDA_hg81

Advanced Member level 2
Joined
Nov 25, 2005
Messages
507
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
4,808
How to convert std_logic_vector to hexadecimal ?

Thanks.
 

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 ?
 

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.
 

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?
 

I am doing a closed loop simulation.

I want to record the feed-back std_logic_vector.

Thanks.
 

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

    EDA_hg81

    Points: 2
    Helpful Answer Positive Rating
are you sure?

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

why?
 

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));
        case quad is
          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!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top