Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.UInt32AlgorithmsExtensions

UInt32AlgorithmsExtensions.PopCount(this uint) Method

Counts the bits that are set to 1 in a number.

public static int PopCount(this uint number);

Parameters

number System.UInt32

The number to evaluate.

Returns

System.Int32 The count of the bits set to 1.

Example

var v = uint.MaxValue;
Console.WriteLine($"{v.PopCount()} bits are set."); // outputs: 32 bits are set.

Remarks

This is an alias for CountBitsSet(this uint).