TYPE CONVERSION

1378 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Sunday

ungelesen,
04.04.2003, 11:24:1704.04.03
an

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)

Ralf Hildebrandt

ungelesen,
04.04.2003, 14:50:4104.04.03
an
Hi "Sunday"!


> 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

Clyde R. Shappee

ungelesen,
06.04.2003, 20:31:5606.04.03
an azby...@club-internet.fr
Here is how I went from std_logic_vector to character.....  using variables.   This compiled under Synplicity.
 

         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

Yahoo

ungelesen,
06.08.2003, 14:12:2006.08.03
an
I copied these lines from some other postings. Search this group for
" Type conversion with characters "

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

Allen antworten
Dem Autor antworten
Weiterleiten
0 neue Nachrichten