public void AddNiblesThenReadByte()
 {
     var sink = new BitSink();
     sink.AddBits(0xE, 4);
     sink.AddBits(0xF, 4);
     Assert.AreEqual(0xFE, sink.Read(8));
 }
        public static IEnumerable<byte> PackBytes(IEnumerable<byte> sourceBytes, int bits)
        {
            var sink = new BitSink();

            foreach (byte sourceByte in sourceBytes)
            {
                sink.AddBits(sourceByte, bits);

                while (sink.CanRead(8))
                {
                    yield return sink.Read(8);
                }
            }

            if (!sink.IsEmpty) yield return sink.ReadRemaining();
        }