Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ788
Page ↗
Q788FWASIC interview problem

Count set bits with Kernighan's method

TechniquesBitsPopcount
DifficultyEasy
TopicBit Manipulation
LanguageSystemVerilog
Requirements2 checkpoints
01

Problem

Return the number of 1 bits in a 32-bit unsigned integer.

Example input and output

Use this case to check your interpretation
Input
value = 8'b1011_0100
Output
4
Explanation

Four iterations clear the lowest remaining one-bit before the value reaches zero.

02

Requirements (2)

  • Clear one set bit per iteration.
  • Return zero for an all-zero input.