You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-16 23:26:32 +09:00
Added missing NetUtility.BitsToHoldUInt64
This commit is contained in:
@@ -282,6 +282,18 @@ namespace Lidgren.Network
|
||||
return bits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns how many bits are necessary to hold a certain number
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public static int BitsToHoldUInt64(ulong value)
|
||||
{
|
||||
int bits = 1;
|
||||
while ((value >>= 1) != 0)
|
||||
bits++;
|
||||
return bits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns how many bytes are required to hold a certain number of bits
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace UnitTests
|
||||
Console.WriteLine("Misc tests OK");
|
||||
|
||||
Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[]{0xDE,0xAD,0xBE,0xEF}));
|
||||
|
||||
if (NetUtility.BitsToHoldUInt64((ulong)UInt32.MaxValue + 1ul) != 33)
|
||||
throw new NetException("BitsToHoldUInt64 failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user