public void TestSetBits2() { byte[] array = new byte[5]; array[3] = 0x00; BitsUtil.SetBits(array, 3, 7, 0, 0x0E3); Assert.AreEqual(array[3], 0xE3); Assert.AreEqual(0xE3, BitsUtil.GetBits(array, 3, 7, 0)); }
public void TestSetBits1() { byte[] array = new byte[5]; array[3] = 0x99; BitsUtil.SetBits(array, 3, 4, 2, 0x02); Assert.AreEqual(array[3], 0x89); Assert.AreEqual(0x02, BitsUtil.GetBits(array, 3, 4, 2)); }
public void TestSetBit() { byte[] array = new byte[5]; array[3] = 0x77; BitsUtil.SetBit(array, 3, 4, 0); Assert.AreEqual(BitsUtil.GetBit(array, 3, 4), false); BitsUtil.SetBit(array, 3, 4); Assert.AreEqual(BitsUtil.GetBit(array, 3, 4), true); BitsUtil.SetBit(array, 3, 4); Assert.AreEqual(BitsUtil.GetBit(array, 3, 4), true); }
/// <summary> /// Only use for fixed parameters or special usage. /// </summary> /// <returns></returns> public static int GetBits(byte[] data, int offset, int highBit, int lowBit) { return(BitsUtil.GetBits(data, offset, highBit, lowBit)); }