static void TestBitfieldSet() { Console.WriteLine("sizeof(ByteBitfield)={0}", System.Runtime.InteropServices.Marshal.SizeOf(typeof(ByteBitfield))); ByteBitfield field = new ByteBitfield(0); while (true) { for (int i = 7; i >= 0; i--) { Console.Write(field.Get(i, 1)); } Console.WriteLine(); Console.WriteLine("Enter a number:"); byte num = Byte.Parse(Console.ReadLine()); Console.WriteLine("Enter an index:"); int index = Int32.Parse(Console.ReadLine()); int size = (int)Math.Log(num, 2) + 1; Console.WriteLine("Size: {0}", size); field.Set(index, num, size); } }
static void TestBitfieldGet() { ByteBitfield field = new ByteBitfield(0); field.Set(4, 15, 4); field.Set(0, 2, 2); while (true) { for (int i = 7; i >= 0; i--) { Console.Write(field.Get(i, 1)); } Console.WriteLine(); Console.WriteLine("Enter an index:"); int index = Int32.Parse(Console.ReadLine()); Console.WriteLine("Enter a length:"); int length = Int32.Parse(Console.ReadLine()); Console.WriteLine("Value: {0}", field.Get(index, length)); } }