Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert HEX to BINARY

581 views
Skip to first unread message

Scott

unread,
Apr 14, 2003, 9:31:07 PM4/14/03
to
Hi All,

I would like to convert HEX to BINARY in VHDL. I am going to convert
decimal numbers to hex on my PC, then send the hex to the FPGA. Once
on the FPGA I will need to convert the hex to binary. My range is 8
bits(so max 255 decimal and FF hex). Im looking for the easiest way.
I suppose I could just write a buntch of if statements and be done
with it.

Anyone have a better idea, or is there a built in function in VHDL
that will do this for me??

Thanks in advance

Scott

Jussi Lähteenmäki

unread,
Apr 15, 2003, 1:38:36 AM4/15/03
to
Scott <scot...@yahoo.com> wrote:
I might be a little off here, but I think hexadecimals are just integers
with a little different notation (or is it syntax). Hence, you merely
type cast integer to, say, std_logic_vector with something like:

constant hex_number: integer := 16#FEC#;

constant binary: STD_LOGIC_VECTOR (13 downto 0) :=
std_logic_vector(to_unsigned(hex_number,14));

remember to include the numeric.std

regards,
juza


: I would like to convert HEX to BINARY in VHDL. I am going to convert

: Thanks in advance

: Scott

--
Juza

Benoit

unread,
Apr 15, 2003, 9:00:16 AM4/15/03
to
Scott,
Use http://www.eda.org/fmf/fmf_public_models/packages/conversions.vhd
with
-- hex string to std_logic_vector
function h (x : string;
rtn_len : positive range 1 to 32 := 32)
return std_logic_vector;

Regards,
Benoit.

"Scott" <scot...@yahoo.com> a écrit dans le message news:
ad642abe.03041...@posting.google.com...

Ralf Hildebrandt

unread,
Apr 15, 2003, 10:28:02 AM4/15/03
to
Hi Scott!


> I would like to convert HEX to BINARY in VHDL.

I posted a quick&dirty solution some days ago:

Message-ID: <b6kouh$6ab5i$3...@ID-8609.news.dfncis.de>
news://b6kouh$6ab5i$3...@ID-8609.news.dfncis.de


Ralf

Scott

unread,
Apr 15, 2003, 8:39:16 PM4/15/03
to
hey Ralf...i wasnt able to connect to the link you sent, something to
do with my lack of authorization. is there any chance you could email
your reponse in that newsgroup? my email is scsul...@csupomona.edu

thanks
scott

Ralf Hildebrandt <Ralf-Hil...@gmx.de> wrote in message news:<b7h5mp$s0gu$2...@ID-8609.news.dfncis.de>...

Ralf Hildebrandt

unread,
Apr 16, 2003, 10:49:20 AM4/16/03
to
Hi "Scott"!

> hey Ralf...i wasnt able to connect to the link you sent, something to
> do with my lack of authorization.

This is a Message-ID. Use http://groups.google.com or a good newsreader.

But now: the source:

-- 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;

Ralf

0 new messages