jkairup
Newbie level 3
I'm trying to make a counter to count the number of the '1' from the input data.
In the simulation part, the result is shown as a 3 bits binary. How to convert the binary to integer.
like in the image, the output "100" , how to use "4" instead of "100". Thank you!
Here is the code.
Thanks!
In the simulation part, the result is shown as a 3 bits binary. How to convert the binary to integer.
like in the image, the output "100" , how to use "4" instead of "100". Thank you!
Here is the code.
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity numb_of_1_counter is
Port ( data : in STD_LOGIC_VECTOR (7 downto 0);
output : out integer range 0 to 8
);
end numb_of_1_counter;
architecture func of numb_of_1_counter is
begin
process (data)
variable temp : integer range 0 to 8;
begin
temp := 0;
for i in 0 to 7 loop
if (data(i) = '1') then
temp := temp + 1;
end if;
end loop;
output <= temp;
end process;
end func;
Thanks!