using System;
namespace UnityEditor.TestTools.TestRunner.GUI.Controls
{
///
/// Provides methods for dealing with common bit operations.
///
internal static class BitUtility
{
///
/// Evaluates the cardinality of an integer, treating the value as a bit set.
/// Optimization based on http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel.
///
/// The input integer value.
/// The number of bits set in the provided input integer value.
internal static int GetCardinality(int integer)
{
unchecked
{
integer = integer - ((integer >> 1) & 0x55555555);
integer = (integer & 0x33333333) + ((integer >> 2) & 0x33333333);
integer = (((integer + (integer >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
}
return integer;
}
}
}