コード例 #1
0
        /// <summary>
        /// Remove zero's of begining of current System.Collections.JIBitArray
        /// </summary>
        /// <returns></returns>
        public JIBitArray RemoveBeginingZeros()
        {
            JIBitArray RArray = new JIBitArray();

            RArray._bits = this._bits;
            while (RArray._bits.Count != 0 && (bool)RArray._bits[0] == false)
            {
                RArray._bits.RemoveAt(0);
            }
            return(RArray);
        }
コード例 #2
0
        /// <summary>
        /// Retrives a SubJIBitArray from this instance. The SubJIBitArray start at the
        /// specified bit position and has specified length
        /// </summary>
        /// <param name="index">The index of the start of SubJIBitArray</param>
        /// <param name="length">The number of bits in SubJIBitArray</param>
        /// <returns></returns>
        public JIBitArray SubJIBitArray(int index, int length)
        {
            JIBitArray RArray = new JIBitArray(length);
            int        c      = 0;

            for (int i = index; i < index + length; i++)
            {
                RArray.Set(c++, (bool)_bits[i]);
            }
            return(RArray);
        }
コード例 #3
0
 /// <summary>
 /// Insert enough zero at the begining of the specified System.Collections.JIBitArray to
 /// make it's lenght to specified length
 /// </summary>
 /// <param name="Value">The System.Collections.JIBitArray with wich to insert zero to begining</param>
 /// <param name="length">The number of bits of Value after inserting</param>
 /// <returns></returns>
 public static JIBitArray FixLength(JIBitArray Value, int length)
 {
     if (length < Value._bits.Count)
     {
         throw(new ArgumentException("length must be equal or greater than Bits.Length"));
     }
     while (Value._bits.Count < length)
     {
         Value._bits.Insert(0, false);
     }
     return(Value);
 }
コード例 #4
0
        /// <summary>
        /// Shift the bits of current System.Collections.JIBitArray as specified number to
        /// right
        /// </summary>
        /// <param name="count">Specific number to shift right</param>
        /// <returns></returns>
        public JIBitArray ShiftRight(int count)
        {
            JIBitArray RArray = new JIBitArray();

            RArray._bits = this._bits;
            for (int i = 0; i < count; i++)
            {
                RArray._bits.RemoveAt(RArray._bits.Count - 1);
                RArray._bits.Insert(0, false);
            }
            return(RArray);
        }
コード例 #5
0
        /// <summary>
        /// Shift the bits of current System.Collections.JIBitArray as specified number to
        /// left
        /// </summary>
        /// <param name="count">Specific number to shift left</param>
        /// <returns></returns>
        public JIBitArray ShiftLeft(int count)
        {
            JIBitArray RArray = new JIBitArray();

            RArray._bits = this._bits;
            for (int i = 0; i < count; i++)
            {
                RArray._bits.RemoveAt(0);
                RArray._bits.Add(false);
            }
            return(RArray);
        }
コード例 #6
0
        /// <summary>
        /// Convert current System.Collections.JIBitArray to a long array
        /// </summary>
        /// <returns></returns>
        public long[] GetLong()
        {
            int ArrayBound = (int)Math.Ceiling((double)this._bits.Count / 64);

            long[]     Bits = new long[ArrayBound];
            JIBitArray Temp = new JIBitArray();

            Temp._bits = this._bits;
            Temp       = FixLength(Temp, ArrayBound * 64);
            for (int i = 0; i < Temp._bits.Count; i += 64)
            {
                Bits[i / 64] = Convert.ToInt64(Temp.SubJIBitArray(i, 64).ToString(), 2);
            }
            return(Bits);
        }
コード例 #7
0
        /// <summary>
        /// Convert current System.Collections.JIBitArray to a byte array
        /// </summary>
        /// <returns></returns>
        public byte[] GetBytes()
        {
            int ArrayBound = (int)Math.Ceiling((double)this._bits.Count / 8);

            byte[]     Bits = new byte[ArrayBound];
            JIBitArray Temp = new JIBitArray();

            Temp._bits = this._bits;
            Temp       = FixLength(Temp, ArrayBound * 8);

            for (int i = 0; i < Temp._bits.Count; i += 8)
            {
                Bits[i / 8] = Convert.ToByte(Temp.SubJIBitArray(i, 8).ToString(), 2);
            }
            return(Bits);
        }
コード例 #8
0
        /// <summary>
        /// Convert current System.Collections.JIBitArray to a short array
        /// </summary>
        /// <returns></returns>
        public short[] GetShorts()
        {
            int ArrayBound = (int)Math.Ceiling((double)this._bits.Count / 16);

            short[]    Bits = new short[ArrayBound];
            JIBitArray Temp = new JIBitArray();

            Temp._bits = this._bits;
            Temp       = FixLength(Temp, ArrayBound * 16);

            for (int i = 0; i < Temp._bits.Count; i += 16)
            {
                Bits[i / 16] = Convert.ToInt16(Temp.SubJIBitArray(i, 16).ToString(), 2);
            }
            return(Bits);
        }
コード例 #9
0
        /// <summary>
        /// Convert current System.Collections.JIBitArray to a int array
        /// </summary>
        /// <returns></returns>
        public int[] GetInt()
        {
            int ArrayBound = (int)Math.Ceiling((double)this._bits.Count / 32);

            int[]      Bits = new int[ArrayBound];
            JIBitArray Temp = new JIBitArray();

            Temp._bits = this._bits;
            Temp       = FixLength(Temp, ArrayBound * 32);

            for (int i = 0; i < Temp._bits.Count; i += 32)
            {
                Bits[i / 32] = Convert.ToInt32(Temp.SubJIBitArray(i, 32).ToString(), 2);
            }
            return(Bits);
        }
コード例 #10
0
        /// <summary>
        /// Inverts all the bits values in the current System.Collections.JIBitArray, so
        /// that elements set to true are changed to false, and elements set to false
        /// are changed to true
        /// </summary>
        /// <returns></returns>
        public JIBitArray Not()
        {
            JIBitArray RArray = new JIBitArray(_bits.Count);

            for (int i = 0; i < _bits.Count; i++)
            {
                if ((bool)_bits[i] == true)
                {
                    RArray.Set(i, false);
                }
                else
                {
                    RArray.Set(i, true);
                }
            }
            return(RArray);
        }
コード例 #11
0
        internal static long GetLong(byte[] arr)
        {
            long       res = 0;
            JIBitArray jb  = new JIBitArray(arr);

            res = 0;
            if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
            {
                jb  = jb.Not();
                res = jb.GetLong()[0];
                res = res + 1;
                res = -1 * res;
            }
            else
            {
                res = jb.GetLong()[0];
            }
            return(res);
        }
コード例 #12
0
        internal static short GetShort(byte[] arr)
        {
            short      res = 0;
            JIBitArray jb  = new JIBitArray(arr);

            res = 0;
            if (jb.Get(0) == true) //Es negativo hay que hacer complemento a 2
            {
                jb  = jb.Not();
                res = jb.GetShorts()[0];
                res = (short)(res + 1);
                res = (short)(-1 * res);
            }
            else
            {
                res = jb.GetShorts()[0];
            }
            return(res);
        }
コード例 #13
0
        /// <summary>
        /// Perform the bitwise eXclusive OR operation on the elements in the current System.Collections.JIBitArray
        /// against the corresponding elements in the specified System.Collections.JIBitArray
        /// </summary>
        /// <param name="Value">The System.Collections.JIBitArray with which to perform the bitwise eXclusive OR operation</param>
        /// <returns></returns>
        public JIBitArray Xor(JIBitArray Value)
        {
            JIBitArray RArray;
            int        Max = _bits.Count > Value._bits.Count ? _bits.Count : Value._bits.Count;

            RArray       = new JIBitArray(Max);
            RArray._bits = this._bits;

            if (Max == RArray._bits.Count)
            {
                FixLength(Value, Max);
            }
            else
            {
                FixLength(RArray, Max);
            }

            for (int i = 0; i < Max; i++)
            {
                RArray.Set(i, (bool)Value._bits[i] ^ (bool)RArray._bits[i]);
            }

            return(RArray);
        }