więc zorientowali się duża część mojego zamieszania jest związane to: IsLittleEndian field reports false, but it must be Little-Endian?
Co skończyło się robi został zawijania cały BitConverter domaga się rozmowy, które miały dodatkowy parametr do specifiy bajt, a następnie dodano funkcję, która jest wywoływana w celu sprawdzenia, czy bajty muszą być czczone.
public static class BitEndianConverter
{
public static byte[] GetBytes(bool value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(char value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(double value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(float value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(int value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(long value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(short value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(uint value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(ulong value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
public static byte[] GetBytes(ushort value, bool littleEndian)
{
return ReverseAsNeeded(BitConverter.GetBytes(value), littleEndian);
}
private static byte[] ReverseAsNeeded(byte[] bytes, bool wantsLittleEndian)
{
if (wantsLittleEndian == BitConverter.IsLittleEndian)
return bytes;
else
return (byte[])bytes.Reverse().ToArray();
}
}
myślę, że to, gdzie jestem mylić choć od BitConverter.IsLittleEndian zwraca false, ale BitConverter.GetBytes() zwraca małe tablice endian. –
Jeśli jest to system Windows, BitConverter.IsLittleEndian, zwracając wartość false, jest oczywiście błędem, ponieważ procesory x86 i x86-64 to Little Endian. – Powerlord