mirror of
https://github.com/aaru-dps/Aaru.Helpers.git
synced 2025-12-16 19:24:35 +00:00
Move to file scoped namespaces.
This commit is contained in:
27
CountBits.cs
27
CountBits.cs
@@ -30,20 +30,19 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.Helpers
|
||||
{
|
||||
/// <summary>Helper operations to count bits</summary>
|
||||
public static class CountBits
|
||||
{
|
||||
/// <summary>Counts the number of bits set to <c>true</c> in a number</summary>
|
||||
/// <param name="number">Number</param>
|
||||
/// <returns>Bits set to <c>true</c></returns>
|
||||
public static int Count(uint number)
|
||||
{
|
||||
number -= (number >> 1) & 0x55555555;
|
||||
number = (number & 0x33333333) + ((number >> 2) & 0x33333333);
|
||||
namespace Aaru.Helpers;
|
||||
|
||||
return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
|
||||
}
|
||||
/// <summary>Helper operations to count bits</summary>
|
||||
public static class CountBits
|
||||
{
|
||||
/// <summary>Counts the number of bits set to <c>true</c> in a number</summary>
|
||||
/// <param name="number">Number</param>
|
||||
/// <returns>Bits set to <c>true</c></returns>
|
||||
public static int Count(uint number)
|
||||
{
|
||||
number -= (number >> 1) & 0x55555555;
|
||||
number = (number & 0x33333333) + ((number >> 2) & 0x33333333);
|
||||
|
||||
return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user