Hi all,
I've some problems with type conversion :
How convert a character into a std_logic_vector (7 downto 0) ? (I've
tried std_logic_vector(value) and to_stdlogicvector(value) but these are
not clodely related types and it's don't work ...)
And ... how to do the inverse, a std_logic_vector (7 downto 0) into a
character ?
Thanks for your help.
Stéphane. (bys...@club-internet.fr)
> How convert a character into a std_logic_vector (7 downto 0) ? (I've
> tried std_logic_vector(value) and to_stdlogicvector(value) but these are
> not clodely related types and it's don't work ...)
Her a quick & _very_ dirty way to do this:
-- convert hex character to 4 bit signed
function char_to_sulv4(char : character) return std_ulogic_vector is
variable res_sulv4: std_ulogic_vector(3 downto 0);
begin
case char is
when ' ' => res_sulv4:="0000";
when '0' => res_sulv4:="0000";
when '1' => res_sulv4:="0001";
when '2' => res_sulv4:="0010";
when '3' => res_sulv4:="0011";
when '4' => res_sulv4:="0100";
when '5' => res_sulv4:="0101";
when '6' => res_sulv4:="0110";
when '7' => res_sulv4:="0111";
when '8' => res_sulv4:="1000";
when '9' => res_sulv4:="1001";
when 'A' => res_sulv4:="1010";
when 'B' => res_sulv4:="1011";
when 'C' => res_sulv4:="1100";
when 'D' => res_sulv4:="1101";
when 'E' => res_sulv4:="1110";
when 'F' => res_sulv4:="1111";
when others => ASSERT (false) REPORT "no hex character read" SEVERITY
failure;
end case;
return res_sulv4;
end char_to_sulv4;
Note: When writing this piece of code, I had only to deal with
characters representing hexadecimal values and spaces. If you want to
convert the full ASCII table, you have to expand this function.
Ralf
x := TO_INTEGER(UNSIGNED
(dout));
c := character'VAL
(x);
This allowed me to have a case statement with a comparison to say, 'e' and make the code more readable.
HTH.
Clyde
int_x <= CHARACTER'POS(char_a);
char_a <= CHARACTER'VAL(int_x);
use ieee.numeric_std.all;
...
slv_vec <= STD_LOGIC_VECTOR(TO_UNSIGNED(CHARACTER'POS(char_a), Nbits));
where Nbits is the number of bits slv_vec'LENGTH.
Good luck,
Troy