Esempio n. 1
0
        public static byte[] UIntToBytes(ulong value, uint length, Endian endian)
        {
            switch (length)
            {
            case 1: return(UInt8ToBytes((byte)value));

            case 2: return(UInt16ToBytes((ushort)value, endian));

            case 4: return(UInt32ToBytes((uint)value, endian));

            case 8: return(UInt64ToBytes(value, endian));

            default: throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        public static ulong BytesToUInt(byte[] buffer, uint startIndex, uint length, Endian endian)
        {
            switch (length)
            {
            case 1: return(BytesToUInt8(buffer, startIndex));

            case 2: return(BytesToUInt16(buffer, startIndex, endian));

            case 4: return(BytesToUInt32(buffer, startIndex, endian));

            case 8: return(BytesToUInt64(buffer, startIndex, endian));

            default: throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 3
0
 public static byte[] Int16ToBytes(short value, Endian endian)
 {
     return(endian == Endian.Little ?
            Int16ToBytesLE(value) :
            Int16ToBytesBE(value));
 }
Esempio n. 4
0
 public static byte[] UInt8ToBytes(byte value, Endian endian)
 {
     return(new byte[] { value });
 }
Esempio n. 5
0
 public static ulong BytesToUInt64(byte[] buffer, uint startIndex, Endian endian)
 {
     return(endian == Endian.Little ?
            BytesToUInt64LE(buffer, startIndex) :
            BytesToUInt64BE(buffer, startIndex));
 }
Esempio n. 6
0
 public static uint BytesToUInt32(byte[] buffer, uint startIndex, Endian endian)
 {
     return(endian == Endian.Little ?
            BytesToUInt32LE(buffer, startIndex) :
            BytesToUInt32BE(buffer, startIndex));
 }
Esempio n. 7
0
 public static ushort BytesToUInt16(byte[] buffer, uint startIndex, Endian endian)
 {
     return(endian == Endian.Little ?
            BytesToUInt16LE(buffer, startIndex) :
            BytesToUInt16BE(buffer, startIndex));
 }
Esempio n. 8
0
 public static byte BytesToUInt8(byte[] buffer, uint startIndex, Endian endian)
 {
     return(buffer[startIndex]);
 }
Esempio n. 9
0
 public static bool BytesToBool(byte[] buffer, uint startIndex, uint length, Endian endian)
 {
     return(endian == Endian.Little ?
            BytesToBoolLE(buffer, startIndex, length) :
            BytesToBoolBE(buffer, startIndex, length));
 }
Esempio n. 10
0
 public static byte[] Int8ToBytes(sbyte value, Endian endian)
 {
     return(new byte[] { (byte)value });
 }
Esempio n. 11
0
 public static byte[] UInt64ToBytes(ulong value, Endian endian)
 {
     return(endian == Endian.Little ?
            UInt64ToBytesLE(value) :
            UInt64ToBytesBE(value));
 }
Esempio n. 12
0
 public static byte[] BoolToBytes(bool value, uint length, Endian endian)
 {
     return(endian == Endian.Little ? BoolToBytesLE(value, length) : BoolToBytesBE(value, length));
 }