Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.UInt64AlgorithmsExtensions

UInt64AlgorithmsExtensions.PopCount(this ulong) Method

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

public static int PopCount(this ulong number);

Parameters

number System.UInt64

The number to evaluate.

Returns

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

Example

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

Remarks

This is an alias for CountBitsSet(this ulong).