コード例 #1
0
        public void BinaryExpression()
        {
            //Creates an instance of BinaryExpression with initial value 13
            var be1 = new BinaryExpression("1101");
            //be1.Length equals to 4 (number of bits)

            //Creates an instance of BinaryExpression with initial value 11
            BinaryExpression be2 = (short)11;
            //be2.Length equals to 16 (number of 'short' type bits)
            var be2_str_2 = be2.ToString();

            //Creates an instance of BinaryExpression with array of bytes constructor parameter.
            var be3 = new BinaryExpression(new byte[] { 128, 58, 15 });
            //be3.Length equals to 24

            //Gets boolean value of bit with specified index.
            bool be1_bit_3 = be1[2];

            be1[2] = false;
            //be1 = 1001 = 9

            int be1_be2_cmp = be1.CompareTo(be2); // = -1, 9 < 11

            bool be1_IsAllTrue = be1.IsAll(true); // = false

            //be2 = 00000000 00001011 = 11, Length = 16
            be2.Length = 10;
            //be2 = 00 00001011 = 11, Length = 10

            be2.Trim();
            //be2 = 1011 = 11, Length = 4

            be1.And((byte)3);
            //be1 = 00000001 = 1, Length = 8

            be1 |= new BinaryExpression("11110000"); // be1.Or
                                                     //be1 = 11110001 = 241, Length = 8

            be3 = be1 << 2;                          //Shift bits to the left
                                                     //be3 = 11000100 = 196, Length = 8
            be3 = be1.RotateLeft(2);                 //Shift circular bits to the left
                                                     //be3 = 11000111 = 199, Length = 8

            be1.Not().Trim();
            //be1 = 1110 = 14, Length = 4

            string binStr = be1.ToString(2); //Base: 2, 8, 10, 16

            //binStr = "1110"

            bool[] bitValues = be1.ToArray();
            //bitValues = [false, true, true, true]
        }