NHSE/NHSE.Core/Util/FlagUtil.cs
Kurt ce631ae722 Add received items list
has button to fill Bugs and Fish list in the Critterpedia
2020-03-29 23:31:29 -07:00

23 lines
712 B
C#

namespace NHSE.Core
{
/// <summary>
/// Utility logic for dealing with bitflags in a byte array.
/// </summary>
public static class FlagUtil
{
public static bool GetFlag(byte[] arr, int offset, int bitIndex)
{
var b = arr[offset + (bitIndex >> 3)];
var mask = 1 << (bitIndex & 7);
return (b & mask) != 0;
}
public static void SetFlag(byte[] arr, int offset, int bitIndex, bool value)
{
offset += (bitIndex >> 3);
bitIndex &= 7; // ensure bit access is 0-7
arr[offset] &= (byte)~(1 << bitIndex);
arr[offset] |= (byte)((value ? 1 : 0) << bitIndex);
}
}
}