Esempio n. 1
0
        public static void WriteBytesToMemStream(this BitArray bitArray, MemoryStream ms)
        {
            if (!bitArray.Check16BitRule())
            {
                throw new Exception("Bit array does not obey 16 bit rule");
            }

            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(bitArray.ToBytes());
        }
Esempio n. 2
0
        public static byte[] ToBytes(this BitArray bitArray)
        {
            if (!bitArray.Check16BitRule())
            {
                throw new Exception("Bit array does not obey 16 bit rule");
            }

            byte[] array = new byte[bitArray.Count / 8];
            bitArray.CopyTo(array, 0);

            return(array);
        }
Esempio n. 3
0
        public static BitArray MergeWith(this BitArray bitArray, BitArray otherBitArray)
        {
            if (!bitArray.Check16BitRule())
            {
                throw new Exception("Bit array does not obey 16 bit rule");
            }

            if (!otherBitArray.Check16BitRule())
            {
                throw new Exception("Other bit array does not obey 16 bit rule");
            }

            byte[] mergedBytes;

            using (MemoryStream ms = new MemoryStream()) {
                bitArray.WriteBytesToMemStream(ms);
                otherBitArray.WriteBytesToMemStream(ms);
                mergedBytes = ms.ToArray();
            }
            return(new BitArray(mergedBytes));
        }