Popcountn
Popcountn is a generalized form of the population count operation in computer science. It computes the number of set bits (bits equal to 1) in the first n bits of an integer, where n is a nonnegative parameter. In some contexts popcountn may refer to counting within an n‑bit word or within a subrange of a word, as defined by a mask. The standard popcount counts all set bits in a word; popcountn narrows the scope to n bits.
Formally, for an integer x and 0 ≤ n ≤ w (the word width) or defined by the mask,
Hardware and software: On modern CPUs, a popcnt instruction returns the popcount of a full word; popcountn
Applications: Popcountn is useful in algorithms that require the density of set bits within a limited range,
See also: population count, bit count, bit masking, bit operations, hardware popcnt.