User-1110131619 posted
I have some old C# code that was supposed to deal with converting Int32s from Host Byte Order to Network Byte Order to pass over a socket. The code has never been tested so even if it is wrong, it may give you some ideas.
The method that retrieves the Int32 from an array of bytes was written to be passed in the array and an index in the array that indicates where to read the Int32. Here are the methods...hope they help...
public static Int32 RetrieveInt32FromBytes( byte[] bytes, ref int startIndex )
{
Int32 value = 0;
value = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, startIndex));
startIndex += 4;
return value;
}
public static byte[] RetrieveBytesFromInt32( Int32 value )
{
byte[] bytes;
bytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)value));
return bytes;
}