Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ563
Page ↗
Q563DVASIC interview problem

Popcount an arbitrary bit vector

TechniquesPacked vectorPopcount
DifficultyEasy
TopicVerification Utilities
LanguageSystemVerilog
Requirements2 checkpoints
01

Problem

Return the number of 1 bits in a packed bit vector.

Example input and output

Use this case to check your interpretation
Input
bits = 12'b1010_0011_0101
Output
6
Explanation

The count covers the full supplied vector width rather than assuming a fixed 32-bit value.

02

Requirements (2)

  • Derive the loop bound from $bits(v).
  • Count only known 1 values.