protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) { if (this.int_5 != 0) { try { System.Type type = typeof(Form); FieldInfo field = type.GetField("FormStateExWindowBoundsWidthIsClientSize", BindingFlags.NonPublic | BindingFlags.Static); FieldInfo info2 = type.GetField("formStateEx", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo info3 = type.GetField("restoredWindowBounds", BindingFlags.NonPublic | BindingFlags.Instance); if (((field != null) && (info2 != null)) && (info3 != null)) { Rectangle rectangle = (Rectangle)info3.GetValue(this); BitVector32.Section section = (BitVector32.Section)field.GetValue(this); BitVector32 vector = (BitVector32)info2.GetValue(this); if (vector[section] == 1) { width = rectangle.Width; height = rectangle.Height; } } } catch { } } base.SetBoundsCore(x, y, width, height, specified); }
protected virtual Size PatchFormSizeInRestoreWindowBoundsIfNecessary(int width, int height) { if (WindowState == FormWindowState.Normal) { try { FieldInfo fiRestoredBoundsSpecified = typeof(Form).GetField("restoredWindowBoundsSpecified", BindingFlags.NonPublic | BindingFlags.Instance); BoundsSpecified restoredSpecified = (BoundsSpecified)fiRestoredBoundsSpecified.GetValue(this); if ((restoredSpecified & BoundsSpecified.Size) != BoundsSpecified.None) { FieldInfo fi1 = typeof(Form).GetField("FormStateExWindowBoundsWidthIsClientSize", BindingFlags.NonPublic | BindingFlags.Static), fiFormState = typeof(Form).GetField("formStateEx", BindingFlags.NonPublic | BindingFlags.Instance), fiBounds = typeof(Form).GetField("restoredWindowBounds", BindingFlags.NonPublic | BindingFlags.Instance); if (fi1 != null && fiFormState != null && fiBounds != null) { Rectangle restoredWindowBounds = (Rectangle)fiBounds.GetValue(this); BitVector32.Section bi1 = (BitVector32.Section)fi1.GetValue(this); BitVector32 state = (BitVector32)fiFormState.GetValue(this); if (state[bi1] == 1) { width = restoredWindowBounds.Width + BorderSize * 2; height = restoredWindowBounds.Height + BorderSize * 2; } } } } catch { } } return(new Size(width, height)); }
static void Main(string[] args) { //для того чтобы сделаь герлянду и чтобы лампочки менялись одновременно - нужно использовать то секции. BitVector32.Section firstSection = BitVector32.CreateSection(10); // 0xA Hex - 1010 Bin //4 байта BitVector32.Section secondSection = BitVector32.CreateSection(50, firstSection); // 0x32 Hex - 110010 Bin BitVector32.Section thirdSection = BitVector32.CreateSection(500, secondSection); // 0x1F4 Hex 111110100 Bin BitVector32.Section fourthSection = BitVector32.CreateSection(500, thirdSection); var packedBits = new BitVector32(0); packedBits[firstSection] = 10; // ....000000000000001010 packedBits[secondSection] = 50; // ....000000001100101010 //т.е добавилось 110010 после 1010 packedBits[thirdSection] = 500; //и так далее packedBits[fourthSection] = 499; //и так далее Console.WriteLine(packedBits[firstSection]); //выведет 10 Console.WriteLine(packedBits[secondSection]); //выведет 50 Console.WriteLine(packedBits[thirdSection]); //выведет 500 Console.WriteLine(packedBits[fourthSection]); //выведет 499 Console.WriteLine(packedBits); //то, что нас интересует Console.WriteLine(packedBits.Data); //выводится число, которое представляет собой последовательность бит. //это число нам ничего не говорит //Delay Console.ReadKey(); }
/// <summary> /// Data used for testing unequal sections. /// </summary> /// Format is: /// 1. Section left /// 2. Section right /// <returns>Row of data</returns> public static IEnumerable <object[]> Section_Unequal_Data() { BitVector32.Section original = BitVector32.CreateSection(16); BitVector32.Section nested = BitVector32.CreateSection(16, original); yield return(new object[] { original, BitVector32.CreateSection(1) }); yield return(new object[] { BitVector32.CreateSection(1), original }); yield return(new object[] { original, nested }); yield return(new object[] { nested, original }); yield return(new object[] { nested, BitVector32.CreateSection(1, BitVector32.CreateSection(short.MaxValue)) }); yield return(new object[] { BitVector32.CreateSection(1, BitVector32.CreateSection(short.MaxValue)), nested }); yield return(new object[] { nested, BitVector32.CreateSection(16, BitVector32.CreateSection(short.MaxValue)) }); yield return(new object[] { BitVector32.CreateSection(16, BitVector32.CreateSection(short.MaxValue)), nested }); yield return(new object[] { nested, BitVector32.CreateSection(1, original) }); yield return(new object[] { BitVector32.CreateSection(1, original), nested }); }
/// <summary> /// Data used for testing equal sections. /// </summary> /// Format is: /// 1. Section left /// 2. Section right /// <returns>Row of data</returns> public static IEnumerable <object[]> Section_Equal_Data() { BitVector32.Section original = BitVector32.CreateSection(16); BitVector32.Section nested = BitVector32.CreateSection(16, original); yield return(new object[] { original, original }); yield return(new object[] { original, BitVector32.CreateSection(16) }); yield return(new object[] { BitVector32.CreateSection(16), original }); // Since the max value is changed to an inclusive mask, equal to mask max value yield return(new object[] { original, BitVector32.CreateSection(31) }); yield return(new object[] { nested, nested }); yield return(new object[] { nested, BitVector32.CreateSection(16, original) }); yield return(new object[] { BitVector32.CreateSection(16, original), nested }); yield return(new object[] { nested, BitVector32.CreateSection(31, original) }); yield return(new object[] { nested, BitVector32.CreateSection(16, BitVector32.CreateSection(16)) }); yield return(new object[] { BitVector32.CreateSection(16, BitVector32.CreateSection(16)), nested }); yield return(new object[] { nested, BitVector32.CreateSection(31, BitVector32.CreateSection(16)) }); // Because it only stores the offset, and not the previous section, later sections may be equal yield return(new object[] { nested, BitVector32.CreateSection(16, BitVector32.CreateSection(8, BitVector32.CreateSection(1))) }); yield return(new object[] { BitVector32.CreateSection(16, BitVector32.CreateSection(8, BitVector32.CreateSection(1))), nested }); }
public static void Main() { // Store and access individual bit values using masks BitVector32 bv1 = new BitVector32(0); Console.WriteLine("bv1 intial value: \t" + (Convert.ToString(bv1.Data, 2)).PadLeft(32, '0')); int bit1 = BitVector32.CreateMask(); int bit2 = BitVector32.CreateMask(bit1); int bit3 = BitVector32.CreateMask(bit2); bv1[bit1] = true; bv1[bit3] = true; Console.WriteLine("bv1 b1 and b3 true: \t" + (Convert.ToString(bv1.Data, 2)).PadLeft(32, '0')); Console.WriteLine("------------------------------------------------------"); // Store and access larger values using sections BitVector32 bv2 = new BitVector32(0); Console.WriteLine("bv2 intial value: \t" + (Convert.ToString(bv2.Data, 2)).PadLeft(32, '0')); BitVector32.Section s1 = BitVector32.CreateSection(8); // uses first 4 bits BitVector32.Section s2 = BitVector32.CreateSection(4, s1); // uses next 3 bits following s1 bv2[s1] = 6; bv2[s2] = 4; Console.WriteLine("bv2 s1 and s2: \t\t" + (Convert.ToString(bv2.Data, 2)).PadLeft(32, '0')); }
public static void Set_Section_OutOfRangeTest(short maximum, int value) { { BitVector32 data = new BitVector32(); BitVector32.Section section = BitVector32.CreateSection(maximum); // In debug mode, attempting to set a value to a section that is too large triggers an assert. // There is no accompanying check in release mode, however, allowing invalid values to be set. #if DEBUG Exception e = Assert.ThrowsAny <Exception>(() => data[section] = value); Assert.Equal("DebugAssertException", e.GetType().Name); #else data[section] = value; Assert.Equal(maximum & value, data.Data); Assert.NotEqual(value, data.Data); Assert.Equal(maximum & value, data[section]); Assert.NotEqual(value, data[section]); #endif } { BitVector32 data = new BitVector32(); BitVector32.Section nested = BitVector32.CreateSection(maximum, BitVector32.CreateSection(short.MaxValue)); #if DEBUG Exception e = Assert.ThrowsAny <Exception>(() => data[nested] = value); Assert.Equal("DebugAssertException", e.GetType().Name); #else data[nested] = value; Assert.Equal((maximum & value) << 15, data.Data); Assert.NotEqual(value << 15, data.Data); Assert.Equal(maximum & value, data[nested]); Assert.NotEqual(value, data[nested]); #endif } }
public static void CreateSection_NextTest(short maximum, short mask) { BitVector32.Section initial = BitVector32.CreateSection(short.MaxValue); BitVector32.Section section = BitVector32.CreateSection(maximum, initial); Assert.Equal(15, section.Offset); Assert.Equal(mask, section.Mask); }
static PlanetManager() { LowBitsMask = BitVector32.CreateSection(0xFF); HighBitsMask = BitVector32.CreateSection(0xFF, LowBitsMask); LongitudeMask = BitVector32.CreateSection(1); //The bit 0 indicates if the longitude is display or not LatitudeMask = BitVector32.CreateSection(1, LongitudeMask); //The bit 1 indicates if the latitude is on DistanceMask = BitVector32.CreateSection(1, LatitudeMask); //The bit 2 indicates if the distance is on LongitudeVelocitiesMask = BitVector32.CreateSection(1, DistanceMask); //The bit 3 indicates if the longitude velocity is display or not LatitudeVelocitiesMask = BitVector32.CreateSection(1, LongitudeVelocitiesMask); //The bit 4 indicates if the latitude velocity is display or not DistanceVelocitiesMask = BitVector32.CreateSection(1, LatitudeVelocitiesMask); //The bit 5 indicates if the distance velocity is display or not AscendingMask = BitVector32.CreateSection(1, DistanceVelocitiesMask); //The bit 6 indicates if the Ascending is displayed or not DescendingMask = BitVector32.CreateSection(1, AscendingMask); //The bit 7 indicates if the Descending is displayed or not PerigeeMask = BitVector32.CreateSection(1, DescendingMask); //The bit 8 indicates if the Perigee is displayed or not ApogeeMask = BitVector32.CreateSection(1, PerigeeMask); //The bit 9 indicates if the Apogee is displayed or not AscendingLatitudeMask = BitVector32.CreateSection(1, ApogeeMask); //The bit 10 indicates if the AscendingLatitude is displayed or not DescendingLatitudeMask = BitVector32.CreateSection(1, AscendingLatitudeMask); //The bit 11 indicates if the DescendingLatitude is displayed or not PerigeeLatitudeMask = BitVector32.CreateSection(1, DescendingLatitudeMask); //The bit 12 indicates if the PerigeeLatitude is displayed or not ApogeeLatitudeMask = BitVector32.CreateSection(1, PerigeeLatitudeMask); //The bit 13 indicates if the ApogeeLatitude is displayed or not AscendingVelocitiesMask = BitVector32.CreateSection(1, ApogeeLatitudeMask); //The bit 14 indicates if the AscendingVelocities is displayed or not DescendingVelocitiesMask = BitVector32.CreateSection(1, AscendingVelocitiesMask); //The bit 15 indicates if the DescendingVelocities is displayed or not PerigeeVelocitiesMask = BitVector32.CreateSection(1, DescendingVelocitiesMask); //The bit 16 indicates if the PerigeeVelocities is displayed or not ApogeeVelocitiesMask = BitVector32.CreateSection(1, PerigeeVelocitiesMask); //The bit 17 indicates if the ApogeeVelocities is displayed or not }
public void SectionIncorrectSize() { BitVector32.Section s1 = BitVector32.CreateSection(32767); BitVector32.Section s2 = BitVector32.CreateSection(32767, s1); BitVector32.Section s3 = BitVector32.CreateSection(4, s2); }
protected override void SetClientSizeCore(int x, int y) { System.Type type = typeof(Control); System.Type type2 = typeof(Form); FieldInfo field = type.GetField("clientWidth", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo info2 = type.GetField("clientHeight", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo info3 = type2.GetField("FormStateSetClientSize", BindingFlags.NonPublic | BindingFlags.Static); FieldInfo info4 = type2.GetField("formState", BindingFlags.NonPublic | BindingFlags.Instance); if (((field != null) && (info2 != null)) && ((info4 != null) && (info3 != null))) { base.Size = new Size(x, y); field.SetValue(this, x); info2.SetValue(this, y); BitVector32.Section section = (BitVector32.Section)info3.GetValue(this); BitVector32 vector = (BitVector32)info4.GetValue(this); vector[section] = 1; info4.SetValue(this, vector); this.OnClientSizeChanged(EventArgs.Empty); vector[section] = 0; info4.SetValue(this, vector); } else { base.SetClientSizeCore(x, y); } }
public void Indexers() { BitVector32 b = new BitVector32(7); Assert.IsTrue(b [0], "#1"); Assert.IsTrue(b [1], "#2"); Assert.IsTrue(b [2], "#3"); Assert.IsTrue(b [4], "#4"); Assert.IsTrue(!b [8], "#5"); Assert.IsTrue(!b [16], "#6"); b [8] = true; Assert.IsTrue(b [4], "#7"); Assert.IsTrue(b [8], "#8"); Assert.IsTrue(!b [16], "#9"); b [8] = false; Assert.IsTrue(b [4], "#10"); Assert.IsTrue(!b [8], "#11"); Assert.IsTrue(!b [16], "#12"); BitVector32.Section s = BitVector32.CreateSection(31); s = BitVector32.CreateSection(64, s); // Print (s); // b = new BitVector32 (0x777777); BitVector32 b1 = new BitVector32(0xffff77); BitVector32 b2 = new BitVector32(b1 [s]); //Console.WriteLine (b1.ToString ()); //Console.WriteLine (b2.ToString ()); Assert.AreEqual(123, b1 [s], "#14"); // b1 [s] = 15; //Console.WriteLine (b1.ToString ()); }
protected override void SetClientSizeCore(int x, int y) { FieldInfo fiWidth = typeof(Control).GetField("clientWidth", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo fiHeight = typeof(Control).GetField("clientHeight", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo fi1 = typeof(Form).GetField("FormStateSetClientSize", BindingFlags.NonPublic | BindingFlags.Static), fiFormState = typeof(Form).GetField("formState", BindingFlags.NonPublic | BindingFlags.Instance); if (fiWidth != null && fiHeight != null && fiFormState != null && fi1 != null) { this.Size = SizeFromClientSize(new Size(x, y)); fiWidth.SetValue(this, x); fiHeight.SetValue(this, y); BitVector32.Section bi1 = (BitVector32.Section)fi1.GetValue(this); BitVector32 state = (BitVector32)fiFormState.GetValue(this); state[bi1] = 1; fiFormState.SetValue(this, state); this.OnClientSizeChanged(EventArgs.Empty); state[bi1] = 0; fiFormState.SetValue(this, state); } else { base.SetClientSizeCore(x, y); } }
public Tuple <ushort, double>[] GetAverages(ushort[] data) { Dictionary <ushort, SensorData> sensors = new Dictionary <ushort, SensorData>(); foreach (var d in data) { BitVector32 item = new BitVector32(d); BitVector32.Section checksum = BitVector32.CreateSection(1); BitVector32.Section sensorData = BitVector32.CreateSection(2067, checksum); BitVector32.Section sensorCode = BitVector32.CreateSection(7, sensorData); if (ChecksumOK(item[checksum], d >> 1)) { ushort code = (ushort)item[sensorCode]; if (!sensors.ContainsKey(code)) { sensors.Add(code, new SensorData { Sum = 0, Count = 0 }); } sensors[code].Sum += item[sensorData]; sensors[code].Count++; } } Tuple <ushort, double>[] result = new Tuple <ushort, double> [sensors.Count]; int index = 0; foreach (var sensor in sensors) { result[index++] = new Tuple <ushort, double>(sensor.Key, (double)sensor.Value.Sum / sensor.Value.Count); } return(result); }
static void Main() { BitVector32.Section firstSection = BitVector32.CreateSection(10); // 0xA Hex - 1010 Bin BitVector32.Section secondSection = BitVector32.CreateSection(50, firstSection); // 0x32 Hex - 110010 Bin BitVector32.Section thirdSection = BitVector32.CreateSection(500, secondSection); // 0x1F4 Hex - 111110100 Bin BitVector32.Section fourthSection = BitVector32.CreateSection(500, thirdSection); var packedBits = new BitVector32(0); packedBits[firstSection] = 10; packedBits[secondSection] = 50; packedBits[thirdSection] = 500; packedBits[fourthSection] = 499; Console.WriteLine(packedBits[firstSection]); Console.WriteLine(packedBits[secondSection]); Console.WriteLine(packedBits[thirdSection]); Console.WriteLine(packedBits[fourthSection]); Console.WriteLine(packedBits); // packedBits = {BitVector32{0000000000000 111110100 110010 1010}} Console.WriteLine(packedBits.Data); // packedBits.Data = 512 810 // Delay. Console.ReadKey(); }
protected override void SetClientSizeCore(int x, int y) { if (_clientWidthField != null && _clientHeightField != null && _formStateField != null && _formStateSetClientSizeField != null) { _clientWidthField.SetValue(this, x); _clientHeightField.SetValue(this, y); BitVector32.Section section = (BitVector32.Section)_formStateSetClientSizeField.GetValue(this); var vector = (BitVector32)_formStateField.GetValue(this); vector[section] = 1; _formStateField.SetValue(this, vector); OnClientSizeChanged(EventArgs.Empty); vector[section] = 0; _formStateField.SetValue(this, vector); Size = SizeFromClientSize(new Size(x, y)); //Size = new Size(x, y); if (startupSize == Size.Empty) { startupSize = Size; } } else { base.SetClientSizeCore(x, y); } }
protected override void SetBoundsCore( int x, int y, int width, int height, BoundsSpecified specified) { if (_inWmWindowPosChanged != 0) { try { Type type = typeof(Form); FieldInfo fi1 = type.GetField("FormStateExWindowBoundsWidthIsClientSize", BindingFlags.NonPublic | BindingFlags.Static), fiFormState = type.GetField("formStateEx", BindingFlags.NonPublic | BindingFlags.Instance), fiBounds = type.GetField("restoredWindowBounds", BindingFlags.NonPublic | BindingFlags.Instance); if (fi1 != null && fiFormState != null && fiBounds != null) { Rectangle restoredWindowBounds = (Rectangle)fiBounds.GetValue(this); BitVector32.Section bi1 = (BitVector32.Section)fi1.GetValue(this); BitVector32 state = (BitVector32)fiFormState.GetValue(this); if (state[bi1] == 1) { width = restoredWindowBounds.Width; height = restoredWindowBounds.Height; } } } catch { } } base.SetBoundsCore(x, y, width, height, specified); }
public void InitFromBytes(byte[] data) { byte[] modulationDataByteArray = new byte[4]; byte[] otherDataByteArray = new byte[4]; Buffer.BlockCopy(data, 0, modulationDataByteArray, 0, 4); Buffer.BlockCopy(data, 4, otherDataByteArray, 0, 4); this.modulationData = BitConverter.ToUInt32(modulationDataByteArray, 0); BitVector32 tempBitVector = new BitVector32(BitConverter.ToInt32(otherDataByteArray, 0)); BitVector32.Section punchthroughAlphaSection = BitVector32.CreateSection(1); BitVector32.Section colorASection = BitVector32.CreateSection(16383 /*(1 << 14) - 1*/, punchthroughAlphaSection); BitVector32.Section colorAIsOpaque = BitVector32.CreateSection(1, colorASection); BitVector32.Section colorBSection = BitVector32.CreateSection(32767 /*(1 << 15) - 1*/, colorAIsOpaque); BitVector32.Section colorBIsOpaque = BitVector32.CreateSection(1, colorBSection); if (tempBitVector[punchthroughAlphaSection] == 1) { this.usePunchthroughAlpha = true; } this.colorA = (uint)tempBitVector[colorASection]; if (tempBitVector[colorAIsOpaque] == 1) { this.colorAIsOpaque = true; } this.colorB = (uint)tempBitVector[colorBSection]; if (tempBitVector[colorBIsOpaque] == 1) { this.colorBIsOpaque = true; } }
public PaletteEntry() { vector = new BitVector32(0); red = BitVector32.CreateSection(31); green = BitVector32.CreateSection(31, red); blue = BitVector32.CreateSection(31, green); stp = BitVector32.CreateSection(1, blue); }
public TexturePageInfo() { vector = new BitVector32(0); page_x = BitVector32.CreateSection(15); page_y = BitVector32.CreateSection(1, page_x); blending_mode = BitVector32.CreateSection(3, page_y); depth = BitVector32.CreateSection(3, blending_mode); }
private static BitVector32.Section partner; //The bits 16-31 together identify the planet pair static RelationKind() { reserved = BitVector32.CreateSection(0xFFF); aspectType = BitVector32.CreateSection(15, reserved); exterior = BitVector32.CreateSection(255, aspectType); interior = BitVector32.CreateSection(255, exterior); partner = BitVector32.CreateSection(Int16.MaxValue, aspectType); }
public void SectionIncorrectSize() { BitVector32.Section s1 = BitVector32.CreateSection(32767); BitVector32.Section s2 = BitVector32.CreateSection(32767, s1); try { BitVector32.Section s3 = BitVector32.CreateSection(4, s2); Assert.Fail("Illegal section created"); } catch (ArgumentException) {} }
public DCB() { this.DCBlength = (uint)Marshal.SizeOf(this); this.Control = new BitVector32(0); this.sect1 = BitVector32.CreateSection(15); this.DTRsect = BitVector32.CreateSection(3, this.sect1); this.sect2 = BitVector32.CreateSection(0x3f, this.DTRsect); this.RTSsect = BitVector32.CreateSection(3, this.sect2); }
private bool IsFormStateClientSizeSet() { FieldInfo fi1 = typeof(Form).GetField("FormStateSetClientSize", BindingFlags.NonPublic | BindingFlags.Static); BitVector32.Section bi1 = (BitVector32.Section)fi1.GetValue(this); BitVector32 state = (BitVector32)FormStateCoreField.GetValue(this); return(state[bi1] == 1); }
public void SectionCorrectSize() { BitVector32.Section s1 = BitVector32.CreateSection(32767); BitVector32.Section s2 = BitVector32.CreateSection(32767, s1); BitVector32.Section s3 = BitVector32.CreateSection(3, s2); BitVector32 v1 = new BitVector32(0); v1[s3] = 3; Assert.AreEqual(v1[s3], 3); }
private static BitVector32.Section yearMask; //The bits 20 - 31 : 12 bits static PoboDayStructure() { minutesMask = BitVector32.CreateSection(0x3F); hoursMask = BitVector32.CreateSection(0x1F, minutesMask); dayMask = BitVector32.CreateSection(0x1F, hoursMask); monthMask = BitVector32.CreateSection(0xF, dayMask); yearMask = BitVector32.CreateSection(0xFFF, monthMask); Size = Marshal.SizeOf(typeof(PoboDayStructure)); }
public void CreateSection() { BitVector32.Section s = BitVector32.CreateSection(1); Assert.AreEqual((short)1, s.Mask, "#1"); s = BitVector32.CreateSection(2); Assert.AreEqual((short)3, s.Mask, "#2"); s = BitVector32.CreateSection(3); Assert.AreEqual((short)3, s.Mask, "#3"); s = BitVector32.CreateSection(5); Assert.AreEqual((short)7, s.Mask, "#4"); s = BitVector32.CreateSection(20); Assert.AreEqual((short)0x1f, s.Mask, "#4"); s = BitVector32.CreateSection(Int16.MaxValue); Assert.AreEqual((short)0x7fff, s.Mask, "#5"); s = BitVector32.CreateSection(Int16.MaxValue - 100); Assert.AreEqual((short)0x7fff, s.Mask, "#6"); try { BitVector32.Section s2 = BitVector32.CreateSection(0); Assert.Fail("#7"); } catch (ArgumentException) {} try { BitVector32.Section s2 = BitVector32.CreateSection(-1); Assert.Fail("#8"); } catch (ArgumentException) {} try { BitVector32.Section s2 = BitVector32.CreateSection(Int16.MinValue); Assert.Fail("#9"); } catch (ArgumentException) {} s = BitVector32.CreateSection(20); Assert.AreEqual((short)0x1f, s.Mask, "#10a"); Assert.AreEqual((short)0x00, s.Offset, "#10b"); s = BitVector32.CreateSection(120, s); Assert.AreEqual((short)0x7f, s.Mask, "#10c"); Assert.AreEqual((short)0x05, s.Offset, "#10d"); s = BitVector32.CreateSection(1000, s); Assert.AreEqual((short)0x3ff, s.Mask, "#10e"); Assert.AreEqual((short)0x0c, s.Offset, "#10f"); }
static void Main(string[] args) { // Create array of 5 elements and 3 true values. bool[] array = new bool[5]; array[0] = true; array[1] = false; // <-- False value is default array[2] = true; array[3] = false; array[4] = true; // Create BitArray from the array. BitArray bitArray = new BitArray(array); // Display all bits. foreach (bool bit in bitArray) { Console.WriteLine(bit); } //Display bits using index into bit array for (int i = 0; i < 5; i++) { Console.WriteLine(bitArray[i]); } //Do XOR BitArray bitArray1 = new BitArray(array); BitArray bitArray2 = bitArray1.Xor(bitArray); //Use BitVector32 to create masks BitVector32 vector = new BitVector32(0); //specifying 0 as initial value make sure all bits are clear int firstBit = BitVector32.CreateMask(); //uses first bit if no param specified int secondBit = BitVector32.CreateMask(firstBit); //passing previous bit mask as param int thirdBit = BitVector32.CreateMask(secondBit); vector[firstBit] = true; vector[secondBit + thirdBit] = true; //vector[secondBit | thirdBit] = true;// this also works Console.WriteLine("Bit vector {0}", vector); Console.WriteLine("Bit vector {0}", vector.Data); Console.WriteLine("Bit vector {0}", vector.ToString()); //Using BitVector32 to do bit packing - ie taking several smaller number and packing them into one large number //Create sections of various sizes to store the smaller numebers - note there is no "new" BitVector32.Section firstSection = BitVector32.CreateSection(10); BitVector32.Section secSection = BitVector32.CreateSection(50, firstSection); BitVector32.Section thirdSection = BitVector32.CreateSection(500, secSection); BitVector32 packedBits = new BitVector32(0); packedBits[firstSection] = 10; packedBits[secSection] = 20; packedBits[thirdSection] = 490; Console.WriteLine(" first sec {0} sec sec {1} third sec {2}", packedBits[firstSection], packedBits[secSection], packedBits[thirdSection]); Console.ReadLine(); }
public static void Section_ToStringTest() { Random random = new Random(-55); short maxValue = (short)random.Next(1, short.MaxValue); BitVector32.Section section1 = BitVector32.CreateSection(maxValue); BitVector32.Section section2 = BitVector32.CreateSection(maxValue); Assert.Equal(section1.ToString(), section2.ToString()); Assert.Equal(section1.ToString(), BitVector32.Section.ToString(section2)); }
public static void Section_Unequal_EqualsTest(BitVector32.Section left, BitVector32.Section right) { Assert.False(left.Equals(right)); Assert.False(right.Equals(left)); Assert.False(left.Equals((object)right)); Assert.False(right.Equals((object)left)); Assert.False(left.Equals(new object())); Assert.False(left == right); Assert.False(right == left); Assert.True(left != right); Assert.True(right != left); }