PopCount - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Bits

  

PopCount

  

compute number of bits that are 1 in an integer

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

PopCount(num)

Parameters

num

-

an integer

Description

• 

The PopCount command computes the number of bits in num that are equal to 1.

• 

If num is negative, infinitely many bits are equal to 1, so the returned value is infinity.

• 

This operation is often called popcount in other systems. The name stands for "population count".

Examples

withBits:

Construct an integer consisting of the following bits.

bits1,1,0,0,0,1,0,1,0,1,1,0,1,1,1

bits1,1,0,0,0,1,0,1,0,1,1,0,1,1,1

(1)

numJoinbits

num30371

(2)

There are 9 bits in num that are equal to 1.

PopCountnum

9

(3)

We can see this by adding the entries of bits, too.

addbits

9

(4)

In fact, PopCount(n) = add(Split(n)) for all positive integers n. It is more efficient to compute PopCount(n) than add(Split(n)).

Compatibility

• 

The Bits[PopCount] command was introduced in Maple 2025.

• 

For more information on Maple 2025 changes, see Updates in Maple 2025.

See Also

Bits

Join

Split