Example #1
0
        public void Write(byte[] bytes, uint bits = 0x0)
        {
            int bitsOfByte = BitTwiddler.BITSOF_BYTE;

            if (bits == 0x0)
            {
                bits = (uint)(bytes.Length * bitsOfByte);
            }

            foreach (byte val in bytes)
            {
                BitTwiddler.FillBits(memory, (uint)val, (bits >= bitsOfByte) ? bitsOfByte : (int)bits, (int)(Iterator / bitsOfByte), (int)(Iterator % bitsOfByte));
                Iterator += (uint)bitsOfByte;
                bits     -= (uint)bitsOfByte;
            }
        }
Example #2
0
        public byte[] Read(uint bits)
        {
            int bitsOfByte = BitTwiddler.BITSOF_BYTE;
            int length     = (int)(bits / bitsOfByte);

            byte[] bytes = new byte[length];

            for (uint i = 0x0; i < length; i++)
            {
                bytes[i]  = (byte)BitTwiddler.GetBits(memory, bitsOfByte, (int)(Iterator / bitsOfByte), (int)(Iterator % bitsOfByte));
                Iterator += (uint)bitsOfByte;
            }

            int leftOver, indLeftOver;

            leftOver    = (int)(Iterator % bitsOfByte);
            indLeftOver = bitsOfByte - leftOver;

            if (leftOver > 0x0)
            {
                bytes[length - 0x1] = (byte)BitTwiddler.ZeroBits(bytes[length - 0x1], leftOver, indLeftOver);
            }
            return(bytes);
        }
Example #3
0
 public void Write(byte val) =>
 BitTwiddler.FillBits(memory, val, BitTwiddler.BITSOF_BYTE, (int)(Iterator / BitTwiddler.BITSOF_BYTE), (int)(Iterator++ % BitTwiddler.BITSOF_BYTE));
Example #4
0
 public void Read(out byte val) =>
 val = (byte)BitTwiddler.GetBits(memory, BitTwiddler.BITSOF_BYTE, (int)(Iterator / BitTwiddler.BITSOF_BYTE), (int)(Iterator++ % BitTwiddler.BITSOF_BYTE));
Example #5
0
 public void Write(bool bit) =>
 BitTwiddler.FillBits(memory, ((bit) ? 0x1u : 0x0u), 0x1, (int)(Iterator / BitTwiddler.BITSOF_BYTE), (int)(Iterator++ % BitTwiddler.BITSOF_BYTE));