ToString() public méthode

public ToString ( ) : string
Résultat string
        static void Main(string[] args)
        {
            /*
            BitVector32 answers = new BitVector32(-1);
            */
            // Creates and initializes a BitVector32 with all bit flags set to FALSE.
            BitVector32 myBV = new BitVector32(0);

            // Creates masks to isolate each of the first five bit flags.
            int myBit1 = BitVector32.CreateMask();
            int myBit2 = BitVector32.CreateMask(myBit1);
            int myBit3 = BitVector32.CreateMask(myBit2);
            int myBit4 = BitVector32.CreateMask(myBit3);
            int myBit5 = BitVector32.CreateMask(myBit4);

            // Sets the alternating bits to TRUE.
            Console.WriteLine("Setting alternating bits to TRUE:");
            Console.WriteLine("   Initial:         {0}", myBV.ToString());
            myBV[myBit1] = true;
            Console.WriteLine("   myBit1 = TRUE:   {0}", myBV.ToString());
            myBV[myBit3] = true;
            Console.WriteLine("   myBit3 = TRUE:   {0}", myBV.ToString());
            myBV[myBit5] = true;
            Console.WriteLine("   myBit5 = TRUE:   {0}", myBV.ToString());

            Console.ReadKey();
        }
Exemple #2
0
        public void Test01()
        {
            BitVector32 bv32;
            BitVector32 bv32Temp;       // extra BitVector32 - for comparison

            // [] BitVector is constructed as expected
            //-----------------------------------------------------------------

            bv32 = new BitVector32();
            if (bv32.Data != 0)
            {
                Assert.False(true, string.Format("Error, Data = {0} after default ctor", bv32.Data));
            }

            string result = bv32.ToString();
            if (result.IndexOf("BitVector32") == -1)
            {  // "BitVector32" is not a part of ToString()
                Assert.False(true, "Error: ToString() doesn't contain \"BitVector32\"");
            }

            bool item = bv32[1];
            if (item)
            {
                Assert.False(true, string.Format("Error: Item(0) returned {0} instead of {1}", item, false));
            }

            bv32Temp = new BitVector32();
            if (!bv32.Equals(bv32Temp))
            {
                Assert.False(true, string.Format("Error: two default vectors are not equal"));
            }
        }
Exemple #3
0
		public void Constructors ()
		{
			BitVector32 b = new BitVector32 (31);
			Assert.AreEqual (31, b.Data, "Data");
			Assert.IsTrue (b.Equals (b), "Equals(self)");
			Assert.IsTrue (b[31], "31");
			Assert.IsFalse (b[32], "32");
			Assert.AreEqual (b.ToString (), "BitVector32{00000000000000000000000000011111}", b.ToString ());

			BitVector32 b2 = new BitVector32 (b);
			Assert.IsTrue (b.Equals (b2), "Equals(b2)");
			Assert.AreEqual (b.GetHashCode (), b2.GetHashCode (), "GetHashCode==");

			b2[32] = true;
			Assert.IsFalse (b.Equals (b2), "Equals(b32)");
			Assert.IsFalse (b.GetHashCode () == b2.GetHashCode (), "GetHashCode!=");
		}
Exemple #4
0
        static void Main(string[] args)
        {
            BitVector32 bv = new BitVector32(1);

            Console.WriteLine(bv.ToString() + " = " + bv.Data);

            int b1 = BitVector32.CreateMask();
            int b2 = BitVector32.CreateMask(b1);
            bv[b1] = true;
            bv[b2] = true;
            Console.WriteLine(bv.ToString() + " = " + bv.Data);

            BitVector32.Section s1 = BitVector32.CreateSection(8);
            BitVector32.Section s2 = BitVector32.CreateSection(10, s1);
            bv[s1] = 8;
            Console.WriteLine(bv.ToString() + " = " + bv.Data);
            Console.WriteLine(bv[s1]);
            bv[s2] = -10;
            Console.WriteLine(bv.ToString() + " = " + bv.Data);
            Console.WriteLine(bv[s2]);
        }
Exemple #5
0
 static void Main(string[] args)
 {
     // Create a BitVector32 with all of its bit flags set to false.
     BitVector32 bv = new BitVector32(0);
     // Create masks to isolate each of the first five bit flags.
     int myBit1 = BitVector32.CreateMask();
     int myBit2 = BitVector32.CreateMask(myBit1);
     int myBit3 = BitVector32.CreateMask(myBit2);
     int myBit4 = BitVector32.CreateMask(myBit3);
     int myBit5 = BitVector32.CreateMask(myBit4);
     // Set alternating bits to true.
     bv[myBit1] = true;
     bv[myBit3] = true;
     bv[myBit5] = true;
     Console.WriteLine(bv.ToString() + " = " + bv.Data);
 }
Exemple #6
0
 static void Main(string[] args)
 {
     // Create a BitVector32 with all of its bits set to 0.
     BitVector32 bv = new BitVector32(0);
     // Create sections with maximum values 6, 3, 1, and 15.
     BitVector32.Section mySect1 = BitVector32.CreateSection(6);
     BitVector32.Section mySect2 = BitVector32.CreateSection(3, mySect1);
     BitVector32.Section mySect3 = BitVector32.CreateSection(1, mySect2);
     BitVector32.Section mySect4 = BitVector32.CreateSection(15, mySect3);
     // Set each section to a value.
     bv[mySect1] = 5;
     bv[mySect2] = 3;
     bv[mySect3] = 1;
     bv[mySect4] = 9;
     Console.WriteLine(bv[mySect4]);
     Console.WriteLine(bv.ToString() + " = " + bv.Data);
 }
		private void Print (BitVector32.Section s)
		{
			Console.WriteLine (s.ToString () + " : "+ s.Mask + " : " + s.Offset);
		}
Exemple #8
0
        private static void RunBitVector32Example()
        {
            // Creates and initializes a BitVector32 with all bit flags set to FALSE.
            BitVector32 myBV = new BitVector32(0);

            // Creates masks to isolate each of the first five bit flags. 
            int myBit1 = BitVector32.CreateMask();
            int myBit2 = BitVector32.CreateMask(myBit1);
            int myBit3 = BitVector32.CreateMask(myBit2);
            int myBit4 = BitVector32.CreateMask(myBit3);
            int myBit5 = BitVector32.CreateMask(myBit4);

            Console.WriteLine("Mask Values: myBit1: {0}, myBit2: {1}, myBit3: {2}, myBit4: {3}, myBit5: {4}", myBit1, myBit2, myBit3, myBit4, myBit5);

            // Sets the alternating bits to TRUE.
            Console.WriteLine("Setting alternating bits to TRUE:");
            Console.WriteLine("   Initial:         {0}", myBV.ToString());
            myBV[myBit1] = true;
            Console.WriteLine("   myBit1 = TRUE:   {0}", myBV.ToString());
            myBV[myBit3] = true;
            Console.WriteLine("   myBit3 = TRUE:   {0}", myBV.ToString());
            myBV[myBit5] = true;
            Console.WriteLine("   myBit5 = TRUE:   {0}", myBV.ToString());

            // Creates and initializes a BitVector32.
            myBV = new BitVector32(0);

            // Creates four sections in the BitVector32 with maximum values 6, 3, 1, and 15. 
            // mySect3, which uses exactly one bit, can also be used as a bit flag.
            BitVector32.Section mySect1 = BitVector32.CreateSection(6);
            BitVector32.Section mySect2 = BitVector32.CreateSection(3, mySect1);
            BitVector32.Section mySect3 = BitVector32.CreateSection(1, mySect2);
            BitVector32.Section mySect4 = BitVector32.CreateSection(15, mySect3);

            // Displays the values of the sections.
            Console.WriteLine("Initial values:");
            Console.WriteLine("\tmySect1: {0}", myBV[mySect1]);
            Console.WriteLine("\tmySect2: {0}", myBV[mySect2]);
            Console.WriteLine("\tmySect3: {0}", myBV[mySect3]);
            Console.WriteLine("\tmySect4: {0}", myBV[mySect4]);

            // Sets each section to a new value and displays the value of the BitVector32 at each step.
            Console.WriteLine("Changing the values of each section:");
            Console.WriteLine("\tInitial:    \t{0}", myBV.ToString());
            myBV[mySect1] = 5;
            Console.WriteLine("\tmySect1 = 5:\t{0}", myBV.ToString());
            myBV[mySect2] = 3;
            Console.WriteLine("\tmySect2 = 3:\t{0}", myBV.ToString());
            myBV[mySect3] = 1;
            Console.WriteLine("\tmySect3 = 1:\t{0}", myBV.ToString());
            myBV[mySect4] = 9;
            Console.WriteLine("\tmySect4 = 9:\t{0}", myBV.ToString());

            // Displays the values of the sections.
            Console.WriteLine("New values:");
            Console.WriteLine("\tmySect1: {0}", myBV[mySect1]);
            Console.WriteLine("\tmySect2: {0}", myBV[mySect2]);
            Console.WriteLine("\tmySect3: {0}", myBV[mySect3]);
            Console.WriteLine("\tmySect4: {0}", myBV[mySect4]);
        }
Exemple #9
0
        static void Main(string[] args)
        {
            System.Collections.ArrayList al;
            System.Collections.BitArray ba;
            System.Collections.Hashtable ht;
            System.Collections.Queue q;
            System.Collections.SortedList sl;
            System.Collections.Stack s;

            System.Collections.Specialized.BitVector32 bv;
            System.Collections.Specialized.HybridDictionary hd;
            System.Collections.Specialized.ListDictionary ld; // Uses a singly linked list which is why it's only good for a few items.
            System.Collections.Specialized.NameValueCollection nvc;
            System.Collections.Specialized.OrderedDictionary od;
            System.Collections.Specialized.StringCollection sc;
            System.Collections.Specialized.StringDictionary sd;

            al = new ArrayList();
            ba = new BitArray(32);
            ht = new Hashtable();
            q = new Queue();
            sl = new SortedList();
            s = new Stack();
            
            //BitVector32... so much fun to be had.
            //RunBitVector32Example();
            
            bool item;
            int trues;
            DateTime start, end;
            start = DateTime.Now;
            item = false;
            trues = 0;
            ba = new BitArray(20);
            for (int i = 0; i < 20; i += 2)
            {
                ba.Set(i, true);
            }
            Console.Write("BitArray {");
            for (int i = 0; i < 20; i++ )
                Console.Write(ba.Get(i) ? "1" : "0");
            Console.WriteLine("}");

            for (int j = 0; j < 1000000; j++)
            {
                for (int i = 0; i < 20; i++)
                {
                    item = ba.Get(i);
                    if (item)
                        trues++;
                }
            }
            end = DateTime.Now;
            Console.WriteLine("{0} trues values were counted...", trues);
            Console.WriteLine("BitArray took: {0}ms", (end - start).TotalMilliseconds.ToString("0.00"));

            bv = new BitVector32();
            start = DateTime.Now;
            item = false;
            trues = 0;
            int l = 1;
            for (int i = 0; i < 10; i++)
            {
                bv[l] = true;
                l *= 4;
            }
            Console.WriteLine(Math.Pow(2, 2));
            Console.WriteLine(bv.ToString());
            for (int j = 0; j < 1000000; j++)
            {
                int k = 1;
                for (int i = 0; i < 20; i++)
                {
                    item = bv[k];
                    k *= 2;
                    if (item)
                        trues++;
                }
            }
            end = DateTime.Now;
            Console.WriteLine("{0} trues values were counted...", trues);
            Console.WriteLine("BitVector32 took: {0}ms", (end - start).TotalMilliseconds.ToString("0.00"));
        }
Exemple #10
0
        public void Test01()
        {
            BitVector32 bv32;
            BitVector32 bv32_1;       // extra BitVector32 - for comparison
            string str = "";              // result of ToString() for bv32
            string str_1 = "";                    // result of ToString() for bv32_1
            int data = 0;

            // [] two BitVectors that are the same should return the same string
            //-----------------------------------------------------------------

            bv32 = new BitVector32();
            bv32_1 = new BitVector32();
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two default structs: \"{0}\" != \"{1}\"", str, str_1));
            }


            // generate random data value
            DateTime time = DateTime.Now;
            data = -55;
            System.Random random = new System.Random(data);
            data = random.Next(System.Int32.MinValue, System.Int32.MaxValue);

            bv32 = new BitVector32(data);
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two equal vectors: \"{0}\" != \"{1}\"", str, str_1));
            }

            bv32 = new BitVector32(data);
            if (data < Int32.MaxValue)
                data++;
            else
                data--;
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) == 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two different vectors: \"{0}\" == \"{1}\"", str, str_1));
            }

            bv32 = new BitVector32();
            str = bv32.ToString();
            str_1 = bv32.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of the same default struct: \"{0}\" != \"{1}\"", str, str_1));
            }

            bv32 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of the same vector: \"{0}\" != \"{1}\"", str, str_1));
            }

            data = 0;
            bv32 = new BitVector32(data);
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data));
            }

            data = 1;
            bv32 = new BitVector32(data);
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data));
            }

            data = -1;
            bv32 = new BitVector32(data);
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data));
            }

            data = Int32.MaxValue;
            bv32 = new BitVector32(data);
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data));
            }

            data = Int32.MinValue;
            bv32 = new BitVector32(data);
            bv32_1 = new BitVector32(data);
            str = bv32.ToString();
            str_1 = bv32_1.ToString();
            if (String.Compare(str, str_1) != 0)
            {
                Assert.False(true, string.Format("Error, ToString() of two {2}-vectors: \"{0}\" != \"{1}\"", str, str_1, data));
            }


            // generate random data value
            time = DateTime.Now;
            data = -55;
            random = new System.Random(data);
            data = random.Next(System.Int32.MinValue, System.Int32.MaxValue);

            bv32 = new BitVector32(data);
            str = bv32.ToString();
            if (str.IndexOf("BitVector32") == -1)
            {
                Assert.False(true, string.Format("Error, ToString() doesn't contain \"BitVector32\""));
            }
        }
Exemple #11
0
 /// <include file='doc\BitVector32.uex' path='docs/doc[@for="BitVector32.ToString1"]/*' />
 /// <internalonly/>
 /// <devdoc>
 /// </devdoc>
 public override string ToString()
 {
     return(BitVector32.ToString(this));
 }