Yeah, for some reason I think I was wrapped around the axle and this
isn't hard at all. I can read the hex digits and make an integer, then
convert that to the unsigned easily. I guess I started with the idea of
converting one bit of result at a time and didn't pull back to see
another way of doing it. It doesn't help that I'm working on this just
before bed time... lol.
Thanks for turning on the light. Here is what I ended up with...
function Hex_to_integer (HexChar : character) return natural is
variable temp : natural;
begin
temp := character'pos(HexChar) - character'pos('0');
if temp > 9 then
temp := temp + character'pos('0') + 10 - character'pos('A');
end if;
if temp > 15 then
temp := temp + character'pos('A') + 10 - character'pos('a');
end if;
assert ((temp >= 0) and (temp <= 15))
report "Error converting '" & HexChar & "' as Hex number"
severity error;
return (temp);
end Hex_to_integer;
function to_unsigned (HexDigits : string; DigCnt : positive)
return unsigned is
variable temp : natural := 0;
variable unsgnd : unsigned (DigCnt-1 downto 0) := (others => '0');
begin
for I in HexDigits'LEFT to HexDigits'RIGHT loop
temp := temp + Hex_to_integer (HexDigits (I));
end loop;
return (to_unsigned(temp, DigCnt));
end to_unsigned;
It seems like more hex related functions should be provided. No?
--
Rick C