Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms Namespace

Provides various software implementations of common bit manipulation algorithms, for C# supported types.

Example

var ul = ulong.MaxValue;

var bitCount = ul.CountBitsSet(); // bitCount = 64;
bitCount = ul.PopCount(); // also 64; this alias is provided for those who like the assembly language term.

var hbs = (ul >> 1).GetHighestBitSet(); // 63

var lbs = (ul << 1).GetLowestBitSet(); // 1

var np2 = 63.RoundUpToPowerOfTwo(); // 64
np2 = 64.RoundUpToPowerOfTwo(); // also 64.

var ip2 = 63.IsPowerOfTwo(); // false
ip2 = 64.IsPowerOfTwo(); // true
ip2 = (-64).IsPowerOfTwo(); // false

var ip = 63.IsPositive(); // true
ip = (-1).IsPositive(); // false

var ie = 63.IsEven(); // false
ie = 64.IsEven(); // true
Classes  
ByteAlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.Byte values.
Int16AlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.Int16 values.
Int32AlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.Int32 values.
Int64AlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.Int64 values.
SByteAlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.SByte values.
UInt16AlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.UInt16 values.
UInt32AlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.UInt32 values.
UInt64AlgorithmsExtensions Provides bit counting and other niche bit manipulation facilities for System.UInt64 values.