Example #1
0
        public void SwapInt16Test()
        {
            // arrange
            Int16 startValue = -0xDEA;
            Int16 expected   = BinaryPrimitives.ReverseEndianness(startValue);

            // act
            Int16 result = BinUtils.SwapEndianess(startValue);

            // assert
            Assert.Equal(expected, result);
        }
Example #2
0
        public void SwapUInt64Test()
        {
            // arrange
            UInt64 startValue = 0xDEADBEEFDEADBE23;
            UInt64 expected   = BinaryPrimitives.ReverseEndianness(startValue);

            // act
            UInt64 result = BinUtils.SwapEndianess(startValue);

            // assert
            Assert.Equal(expected, result);
        }
Example #3
0
        public static void WriteVlv(this byte[] data, UInt32 value, ref int offset)
        {
            Debug.Assert(value <= 0xfffffff);

            uint   byteCount = 1;
            UInt32 store     = value & 0x7F;

            value >>= 7;

            while (value != 0)
            {
                store <<= 8;
                store  |= (value & 0x7F) | 0x80;
                value >>= 7;
                byteCount++;
            }

            BinUtils.SwapEndianess(store);
            Unsafe.CopyBlockUnaligned(ref Unsafe.As <UInt32, byte>(ref store), ref data[offset], byteCount);
            Console.WriteLine(byteCount);
            offset += (int)byteCount;
        }