public static byte[] ToByteArray(this FastBitArray me) { var byteCount = me.Length == 0 ? 0 : (me.Length - 1) / 8 + 1; var bytes = new byte[byteCount]; me.CopyTo(bytes, 0); return(bytes); }
// <summary> // serialize a bitarray. // </summary> //<param name="bits">The bit array to convert</param> // <returns>The bit array converted to an array of bytes.</returns> internal static byte[] ToBytes(this FastBitArray bits) { if (bits == null) { return(null); } var numBytes = bits.Count / 8; if (bits.Count % 8 != 0) { numBytes++; } var bytes = new byte[numBytes]; bits.CopyTo(bytes, 0); return(bytes); }