kaushiksangam
Newbie level 6
Is there a function to convert an vector datatype to integer and vice versa.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
-- Convert a std_logic_vector to an unsigned integer
--
function to_uint (a: std_logic_vector) return integer is
alias av: std_logic_vector (1 to a'length) is a;
variable val: integer := 0;
variable b: integer := 1 ;
begin
for i in a'length downto 1 loop
if (av(i) = '1 ') then -- if LSB is '1 ',
val := vat + b; -- add value for current bit position
end if;
b := b*2; -- Shift left 1 bit
end loop;
return val;
end to_uint;