FastPrepCount Ones in a 16-bit Word
Problems/Count Ones in a 16-bit Word

Count Ones in a 16-bit Word

Xilinx logoXilinx● EasyNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report explicitly asks for a 16-bit population count, Verilog and its synthesized circuit. This practice grades a software count and retains the hardware discussion as a follow-up; it does not claim RTL or synthesis validation. The callable interface and examples are authored. Approximate source match: 80%.

Return the number of set bits in the unsigned 16-bit value word.

Hardware follow-up: explain how to write the same population count in Verilog and what combinational structure synthesis can infer. The executable task checks the numeric count; it does not compile HDL or grade a circuit drawing.

Function

countOnes16(word: int) → int

Examples

Example 1

word = 0return = 0

Zero has no set bits.

Example 2

word = 13return = 3

13 is binary 1101, which has three 1 bits.

Example 3

word = 65535return = 16

65535 has all sixteen bits set.

Constraints

  • 0 <= word <= 65535.

More Xilinx problems

  • Delete a Given Linked-list NodeONSITE INTERVIEW · Seen Feb 2019
  • Reservation-station Tag MatchONSITE INTERVIEW · Seen Feb 2019
  • Sort with Two-input ComparatorsONSITE INTERVIEW · Seen Feb 2019
All Xilinx interview questionsSee Xilinx hiring insights
Saved
public int countOnes16(int word) {
    return 0;
}
Checking account…