Exemple #1
0
        public static byte[] GetBytesWithEndianBit(this Int64 inValue, EndianBitType desType = EndianBitType.LittleEndian)
        {
            var b = new byte[8];

            ToBytesWithEndianBit(inValue, b, 0, desType);
            return(b);
        }
Exemple #2
0
        public static UInt32 GetUInt32WithEndianBit(this byte[] src, int index = 0, EndianBitType srcType = EndianBitType.LittleEndian)
        {
            CheckArguments(src, index, sizeof(UInt32));
            UInt32 result    = (UInt32)((src[index]) | (src[index + 1] << 8) | (src[index + 2] << 16) | (src[index + 3] << 24));
            bool   isNeedRev = false;

            if (BitConverter.IsLittleEndian && srcType == EndianBitType.BigEndian)
            {
                isNeedRev = true;
            }
            if (isNeedRev)
            {
                result = ReverseBytes(result);
            }
            return(result);
        }
Exemple #3
0
        public static Int64 GetInt64WithEndianBit(this byte[] src, int index = 0, EndianBitType srcType = EndianBitType.LittleEndian)
        {
            UInt64 result = GetUInt64WithEndianBit(src, index, srcType);

            return(BytesN8Union.Create(result).sint64vluae);
        }
Exemple #4
0
        public static void ToBytesWithEndianBit(this Int64 inValue, byte[] des, int index = 0, EndianBitType desType = EndianBitType.LittleEndian)
        {
            UInt64 _convert = BytesN8Union.Create(inValue).GetValue();

            ToBytesWithEndianBit(_convert, des, index, desType);
        }
Exemple #5
0
        public static void ToBytesWithEndianBit(this UInt64 inValue, byte[] des, int index = 0, EndianBitType desType = EndianBitType.LittleEndian)
        {
            bool isNeedRev = false;

            if (BitConverter.IsLittleEndian && desType == EndianBitType.BigEndian)
            {
                isNeedRev = true;
            }
            UInt64 result = inValue;

            if (isNeedRev)
            {
                result = ReverseBytes(result);
            }

            des[index + 0] = (byte)(result & 0xFFUL);
            des[index + 1] = (byte)((result & 0xFF00UL) >> 8);
            des[index + 2] = (byte)((result & 0xFF0000UL) >> 16);
            des[index + 3] = (byte)((result & 0xFF000000UL) >> 24);
            des[index + 4] = (byte)((result & 0xFF00000000UL) >> 32);
            des[index + 5] = (byte)((result & 0xFF0000000000UL) >> 40);
            des[index + 6] = (byte)((result & 0xFF000000000000UL) >> 48);
            des[index + 7] = (byte)((result & 0xFF00000000000000UL) >> 56);
        }
Exemple #6
0
        public static void ToBytesWithEndianBit(this UInt16 inValue, byte[] des, int index = 0, EndianBitType desType = EndianBitType.LittleEndian)
        {
            bool isNeedRev = false;

            if (BitConverter.IsLittleEndian && desType == EndianBitType.BigEndian)
            {
                isNeedRev = true;
            }
            UInt16 result = inValue;

            if (isNeedRev)
            {
                result = ReverseBytes(result);
            }

            des[index + 0] = (byte)(result & 0xFFU);
            des[index + 1] = (byte)((result & 0xFF00U) >> 8);
        }