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.

Need help in VHDL function for Vector to string conversion.

Status
Not open for further replies.

rocking1234

Member level 1
Joined
May 2, 2009
Messages
36
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
India
Activity points
1,535
Hi
I am newbie to VHDL, I have a function here to convert the STD_LOGIC_VECTOR to STring conversion.

-------------------------------------------
function hex_to_string(Value: in std_logic_vector) return string is

variable extended_value : std_logic_vector((Value'length + 3 - (Value'length mod 4)) downto 0) := (others => '0');
variable current_digit : std_logic_vector(3 downto 0);
variable num_digits : integer;
variable Result : string(Value'length downto 1);

begin
extended_value(value'length-1 downto 0) :=value;

num_digits := value'length / 4;
if (Value'length mod 4) /= 0 then
num_digits := num_digits+1;
end if;

for I in num_digits downto 1 loop

Current_digit := extended_value(i*4-1 downto (i-1)*4);
case Current_Digit is
when X"0" => Result(I downto I) := string'("0");
when X"1" => Result(I downto I) := string'("1");
when X"2" => Result(I downto I) := string'("2");
when X"3" => Result(I downto I) := string'("3");
when X"4" => Result(I downto I) := string'("4");
when X"5" => Result(I downto I) := string'("5");
when X"6" => Result(I downto I) := string'("6");
when X"7" => Result(I downto I) := string'("7");
when X"8" => Result(I downto I) := string'("8");
when X"9" => Result(I downto I) := string'("9");
when X"A" => Result(I downto I) := string'("A");
when X"B" => Result(I downto I) := string'("B");
when X"C" => Result(I downto I) := string'("C");
when X"D" => Result(I downto I) := string'("D");
when X"E" => Result(I downto I) := string'("E");
when X"F" => Result(I downto I) := string'("F");
when others => Result(I downto I) := string'(".");
end case;
end loop;
return result(Num_digits downto 1);
end;

Could some1 explain whats going on ...I would be helpful
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top