Example #1
0
        public void TestBitArray()
        {
            BitArray bits = new BitArray(64);

            bits[0]  = true;
            bits[21] = true;
            byte[] bytes = new byte[8];
            bits.CopyTo(bytes, 0);

            //ulong dataValue = BitConverter.ToUInt64(bytes, 0) << 0;
            ulong dataValue = 1 << 20;

            Console.WriteLine($"{dataValue:x2}");
            Console.WriteLine($"{Convert.ToString((long) dataValue, 2)}");

            var stream = new MemoryStream();

            VarInt.WriteUInt64(stream, dataValue);

            byte[] array = stream.ToArray();
            Console.WriteLine($"{Package.HexDump(array)}");


            //var result = VarInt.ReadUInt64(new MemoryStream(array));
            var result = VarInt.ReadUInt64(new MemoryStream(new byte[] { 0x80, 0x80, 0x80, 0x11 }));

            Console.WriteLine($"{Convert.ToString((long) result, 2)}");

            //Assert.AreEqual(dataValue, result);
            Console.WriteLine($"{dataValue:x2}");

            //81808080808080808001                    €€€€€€€€.
        }
Example #2
0
 public long ReadUnsignedVarLong()
 {
     // Need to fix this to ulong later
     return((long)VarInt.ReadUInt64(_buffer));
 }