public static Int32 ToInt32(byte[] data, int start, Int32Swap swap) { var t1 = new byte[4]; switch (swap) { case Int32Swap.C0123: t1[0] = data[3 + start]; t1[1] = data[2 + start]; t1[2] = data[1 + start]; t1[3] = data[0 + start]; break; case Int32Swap.C3210: t1[0] = data[0 + start]; t1[1] = data[1 + start]; t1[2] = data[2 + start]; t1[3] = data[3 + start]; break; case Int32Swap.C1032: t1[0] = data[1 + start]; t1[1] = data[0 + start]; t1[2] = data[3 + start]; t1[3] = data[2 + start]; break; } return(BitConverter.ToInt32(t1, 0)); }
public static byte[] GetBytes(Int32 value, Int32Swap longSwap) { byte[] t = null; t = BitConverter.GetBytes(value); switch (longSwap) { case Int32Swap.C3210: //本身转换过后的值就是低位在前 break; case Int32Swap.C0123: var t1 = new byte[4]; t1[0] = t[3]; t1[1] = t[2]; t1[2] = t[1]; t1[3] = t[0]; t = t1; break; } return(t); }