protected uint[] constructUIntArrayFromUInt32(int machinecode, byte[] data) { var result = new uint[data.Length / 4]; if (machinecode == 6) { for (int i = 0; i < result.Length; i++) { result[i] = PickleUtils.bytes_to_uint(data, i * 4); } } else { var bigendian = new byte[4]; for (int i = 0; i < result.Length; i++) { // big endian, swap bigendian[0] = data[3 + i * 4]; bigendian[1] = data[2 + i * 4]; bigendian[2] = data[1 + i * 4]; bigendian[3] = data[0 + i * 4]; result[i] = PickleUtils.bytes_to_uint(bigendian, 0); } } return(result); }
public void TestBytes_to_uint() { try { PickleUtils.bytes_to_uint(new byte[] {}, 0); Assert.True(false, "expected PickleException"); } catch (PickleException) {} try { PickleUtils.bytes_to_uint(new byte[] { 0 }, 0); Assert.True(false, "expected PickleException"); } catch (PickleException) {} Assert.Equal(0x000000000L, PickleUtils.bytes_to_uint(new byte[] { 0, 0, 0, 0 }, 0)); Assert.Equal(0x012345678L, PickleUtils.bytes_to_uint(new byte[] { 0x78, 0x56, 0x34, 0x12 }, 0)); Assert.Equal(0x0ff802040L, PickleUtils.bytes_to_uint(new byte[] { 0x40, 0x20, 0x80, 0xff }, 0)); Assert.Equal(0x0eefffffeL, PickleUtils.bytes_to_uint(new byte[] { 0xfe, 0xff, 0xff, 0xee }, 0)); }