Problems

2. Count the ones

EasyWrite the moduleAbout 10 minFree
combinationalpopulation countparity

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

Module popcount8

PortDirBitsWhat it is
din8The value to inspect.
countout4Number of 1 bits in d (0 to 8).
parityout11 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.

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Verilogpopcount8.v
14px
Loading the editor…

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.

Count the ones: Verilog interview question | breadboardhub