public void SetBit(BitFlagArray array, int bitNumber, bool newValue) { if (newValue) { SetBitTrue(array, bitNumber); return; } SetBitFalse(array, bitNumber); }
public bool IsFlagTrue(BitFlagArray array, ushort flag) { var bitToCheck = -1; var newFlag = 0; // 1, 2, 4, 8 // 16, 32, 64, 128 // 256, 512, 1024, 2048 // 2048, 4096, 8192, 16384 for (var iGroup = 3; iGroup >= 0; iGroup--) { if ((newFlag = (flag >> iGroup)) > 0) { if (newFlag == 1) { bitToCheck = 1 + iGroup * 4; } else if (newFlag == 2) { bitToCheck = 2 + iGroup * 4; } else if (newFlag == 4) { bitToCheck = 3 + iGroup * 4; } else if (newFlag == 8) { bitToCheck = 4 + iGroup * 4; } if (bitToCheck != -1) { return(IsBitTrue(array, bitToCheck)); } } } return(false); }
public void SetByteAt(BitFlagArray array, int byteIndex, byte byteValue) { array.Bytes[byteIndex] = byteValue; }
public void SetBitFalse(BitFlagArray array, int bitNumber) { // using the ~ returns an int; have to turn it back into a byte array.Bytes[CalculateBitOffset(bitNumber)] &= (byte)~CalculateBitMask(bitNumber); }
public void SetBitTrue(BitFlagArray array, int bitNumber) { array.Bytes[CalculateBitOffset(bitNumber)] |= CalculateBitMask(bitNumber); }
public bool IsBitFalse(BitFlagArray array, int bitNumber) { return(!IsBitTrue(array, bitNumber)); }
public int ByteLength(BitFlagArray array) { return(array.Bytes.Length); }
public bool IsBitTrue(BitFlagArray array, int bitNumber) { return((array.Bytes[CalculateBitOffset(bitNumber)] >> (CalculateByteOffset(bitNumber) & 0x1f) & 1) != 0); }
public byte GetByteAt(BitFlagArray array, int byteIndex) { return(array.Bytes[byteIndex]); }
public void Copy(BitFlagArray array, byte[] buffer, int startingPosition) { System.Array.Copy(array.Bytes, 0, buffer, startingPosition, array.Bytes.Length); }