I want to count the number of 1's in an 8-bit input and output how many ones are in it. The way I am finding this is very crude and redundant. I want to know if there is any easy and good way of finding them. My code looks like:
module my_8to4bit(in,out); input [7:0]in; output [3:0]out; assign out=(input == 1 || input == 2 || input == 4 || input == 8 || input == 16 || input == 32 || input == 64 || input == 128)?1: (input == 3 || input == 5 || input == 6 || input == 9 || input == 10 || input == 12 || input == 24 || input == 128)?2:0; ... same goes upto all 1's in 8bit input.
Is there an easy way of finding them?
input == 128) ? 2:0