public void Should_Align() { var stream = new BitStream(); stream.Write((UInt2)2); stream.Write((UInt4)7); // 6 bits written Assert.AreEqual(UInt2.BitSize + UInt4.BitSize, stream.BitsPosition); // align the bits (write 2 0 bits) stream.Align(); // write a full byte. stream.WriteByte(0xFF); var bytes = stream.ToArray(); // 01 + 1110 = 30 // 1111 1111 = 255 Assert.AreEqual(new byte[] { 30, 255 }, bytes); }