using System; namespace PKHeX.Core; /// /// Utility logic for dealing with bitflags in a byte array. /// public static class FlagUtil { /// /// Gets the requested from the byte at . /// /// Buffer to read /// Offset of the byte /// Bit to read public static bool GetFlag(ReadOnlySpan arr, int offset, int bitIndex) { bitIndex &= 7; // ensure bit access is 0-7 return ((arr[offset] >> bitIndex) & 1) != 0; } /// /// Sets the requested value to the byte at . /// /// Buffer to modify /// Offset of the byte /// Bit to write /// Bit flag value to set public static void SetFlag(Span arr, int offset, int bitIndex, bool value) { bitIndex &= 7; // ensure bit access is 0-7 var current = arr[offset] & ~(1 << bitIndex); var newValue = current | ((value ? 1 : 0) << bitIndex); arr[offset] = (byte)newValue; } }