2. Count the ones
Build a combinational module that looks at an 8-bit value and reports how many of its bits are 1 (its population count), and whether that number is odd (its parity).
count is the number of 1 bits, from 0 to 8, so it needs 4 bits. parity is 1 when the number of 1 bits is odd and 0 when it is even. There is no clock and no reset.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
d | in | 8 | The value to inspect. |
count | out | 4 | Number of 1 bits in d (0 to 8). |
parity | out | 1 | 1 when count is odd. |
Example
d = 1010_0110 has four 1 bits: count = 4, parity = 0. d = 0001_0011 has three: count = 3, parity = 1.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.