/// <seealso cref="BitArrayOutputStream.write(int)">
        /// </seealso>
        public virtual void testWrite()
        {
            BitArrayOutputStream stream = new BitArrayOutputStream();
            stream.WriteByte(0xFF);
            stream.writeBit(true);
            stream.writeBit(false);
            stream.writeBit(true);
            stream.writeBit(false);
            stream.WriteByte(0xFF);
            stream.WriteByte(0x0F);
            stream.writeBit(true);
            stream.writeBit(true);
            stream.writeBit(true);
            stream.writeBit(true);
            System.Console.Out.WriteLine("Write " + ByteTools.byteArrayToHexString(stream.ToArray()));
            ByteTools.checkBuffers(stream.ToArray(), new byte[] { 0xFF, 0xAF, 0xF0, 0xFF });

            stream.writeBit(true);
            stream.writeBit(false);
            stream.writeBit(true);
            stream.writeBit(false);
            byte[] temp_byteArray;
            temp_byteArray = new byte[]{ (0xCC),  (0xFF),  (0xFF),  (0xBB)};
            stream.Write(temp_byteArray, 0, temp_byteArray.Length);
            System.Console.Out.WriteLine("After buf write " + ByteTools.byteArrayToHexString(stream.ToArray()));
            ByteTools.checkBuffers(stream.ToArray(), new byte[]{ (0xFF),  (0xAF),  (0xF0),  (0xFF),  (0xAC),  (0xCF),  (0xFF),  (0xFB),  (0xB0)});
            stream.align();
            stream.writeBit(true);
            stream.writeBit(true);
            stream.align();
            stream.WriteByte(0xFF);

            System.Console.Out.WriteLine("After align " + ByteTools.byteArrayToHexString(stream.ToArray()));
            ByteTools.checkBuffers(stream.ToArray(), new byte[]{ (0xFF),  (0xAF),  (0xF0),  (0xFF),  (0xAC),  (0xCF),  (0xFF),  (0xFB),  (0xB0),  (0xC0),  (0xFF)});
        }
Esempio n. 2
0
        protected override int encodeConstraintNumber(long val, long min, long max, BitArrayOutputStream stream)
        {
            int result = 0;
            long valueRange = max - min;
            long narrowedVal = val - min;
            int maxBitLen = PERCoderUtils.getMaxBitLength(valueRange);

            if (valueRange == 0)
            {
                return result;
            }

            //For the UNALIGNED variant the value is always encoded in the minimum
            // number of bits necessary to represent the range (defined in 10.5.3).
            int currentBit = maxBitLen;
            while (currentBit > 8)
            {
                currentBit -= 8;
                result++;
                stream.WriteByte((byte) (narrowedVal >> currentBit));
            }
            if (currentBit > 0)
            {
                for (int i = currentBit - 1; i >= 0; i--)
                {
                    int bitValue = (int) ((narrowedVal >> i) & 0x1);
                    stream.writeBit(bitValue);
                }
                result += 1;
            }
            return result;
        }
Esempio n. 3
0
        public virtual void testWrite()
        {
            BitArrayOutputStream stream = new BitArrayOutputStream();

            stream.WriteByte(0xFF);
            stream.writeBit(true);
            stream.writeBit(false);
            stream.writeBit(true);
            stream.writeBit(false);
            stream.WriteByte(0xFF);
            stream.WriteByte(0x0F);
            stream.writeBit(true);
            stream.writeBit(true);
            stream.writeBit(true);
            stream.writeBit(true);
            System.Console.Out.WriteLine("Write " + ByteTools.byteArrayToHexString(stream.ToArray()));
            ByteTools.checkBuffers(stream.ToArray(), new byte[] { 0xFF, 0xAF, 0xF0, 0xFF });

            stream.writeBit(true);
            stream.writeBit(false);
            stream.writeBit(true);
            stream.writeBit(false);
            byte[] temp_byteArray;
            temp_byteArray = new byte[] { (0xCC), (0xFF), (0xFF), (0xBB) };
            stream.Write(temp_byteArray, 0, temp_byteArray.Length);
            System.Console.Out.WriteLine("After buf write " + ByteTools.byteArrayToHexString(stream.ToArray()));
            ByteTools.checkBuffers(stream.ToArray(), new byte[] { (0xFF), (0xAF), (0xF0), (0xFF), (0xAC), (0xCF), (0xFF), (0xFB), (0xB0) });
            stream.align();
            stream.writeBit(true);
            stream.writeBit(true);
            stream.align();
            stream.WriteByte(0xFF);

            System.Console.Out.WriteLine("After align " + ByteTools.byteArrayToHexString(stream.ToArray()));
            ByteTools.checkBuffers(stream.ToArray(), new byte[] { (0xFF), (0xAF), (0xF0), (0xFF), (0xAC), (0xCF), (0xFF), (0xFB), (0xB0), (0xC0), (0xFF) });
        }