<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0-preview.4.23259.5" />

BitOperations

static class BitOperations
using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Numerics { internal static class BitOperations { private unsafe static ReadOnlySpan<byte> Log2DeBruijn => new ReadOnlySpan<byte>(&global::<PrivateImplementationDetails>.4BCD43D478B9229AB7A13406353712C7944B60348C36B4D0E6B789D10F697652, 32); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Log2(uint value) { return Log2SoftwareFallback(value | 1); } private unsafe static int Log2SoftwareFallback(uint value) { value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; value |= value >> 16; return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(Log2DeBruijn), (IntPtr)(void*)(value * 130329821 >> 27)); } } }