예제 #1
0
        public static void WriteBytesBE(this ushort val, byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, UINT16_SIZE, "offset", "offset");

            buffer[offset]     = (byte)(val >> 8);
            buffer[offset + 1] = (byte)val;
        }
예제 #2
0
        public static void WriteBytes(this uint val, byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, UINT32_SIZE, "offset", "offset");

            buffer[offset]     = (byte)val;
            buffer[offset + 1] = (byte)(val >> 8);
            buffer[offset + 2] = (byte)(val >> 16);
            buffer[offset + 3] = (byte)(val >> 24);
        }
예제 #3
0
        public static ushort ReadUInt16BE(this byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, UINT16_SIZE, "offset", "offset");

            ushort val = (ushort)(((uint)buffer[offset]) << 8);

            val |= buffer[offset + 1];

            return(val);
        }
예제 #4
0
        public static uint ReadUInt32(this byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, UINT32_SIZE, "offset", "offset");

            uint val = buffer[offset];

            val |= ((uint)buffer[offset + 1]) << 8;
            val |= ((uint)buffer[offset + 2]) << 16;
            val |= ((uint)buffer[offset + 3]) << 24;

            return(val);
        }
예제 #5
0
        public static void WriteBytesBE(this ulong val, byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, UINT64_SIZE, "offset", "offset");

            buffer[offset]     = (byte)(val >> 56);
            buffer[offset + 1] = (byte)(val >> 48);
            buffer[offset + 2] = (byte)(val >> 40);
            buffer[offset + 3] = (byte)(val >> 32);
            buffer[offset + 4] = (byte)(val >> 24);
            buffer[offset + 5] = (byte)(val >> 16);
            buffer[offset + 6] = (byte)(val >> 8);
            buffer[offset + 7] = (byte)val;
        }
예제 #6
0
        public static ulong ReadUInt64BE(this byte[] buffer, int offset)
        {
            ContractsCommon.NotNull(buffer, "buffer");
            ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, UINT64_SIZE, "offset", "offset");

            ulong val = ((ulong)buffer[offset]) << 56;

            val |= ((ulong)buffer[offset + 1]) << 48;
            val |= ((ulong)buffer[offset + 2]) << 40;
            val |= ((ulong)buffer[offset + 3]) << 32;
            val |= ((ulong)buffer[offset + 4]) << 24;
            val |= ((ulong)buffer[offset + 5]) << 16;
            val |= ((ulong)buffer[offset + 6]) << 8;
            val |= buffer[offset + 7];

            return(val);
        }