Added helper to count bits from uint.

This commit is contained in:
2017-07-10 21:37:19 +01:00
parent 3fcfa7f10d
commit 27b57768e4
2 changed files with 6 additions and 2 deletions

View File

@@ -32,10 +32,13 @@
using System;
namespace DiscImageChef.Helpers
{
public class CountBits
public static class CountBits
{
public CountBits()
public static int Count(uint number)
{
number = number - ((number >> 1) & 0x55555555);
number = (number & 0x33333333) + ((number >> 2) & 0x33333333);
return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
}
}
}

View File

@@ -53,6 +53,7 @@
<Compile Include="Extents\ExtentsUShort.cs" />
<Compile Include="Extents\ExtentsByte.cs" />
<Compile Include="Extents\ExtentsSByte.cs" />
<Compile Include="CountBits.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>