rocking1234
Member level 1
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
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