Reverse int value byte order. Static function in IPAddress class doesn't work the way I expected it (didn't troubleshoot) so here is another implementation. Reversing byte order is needed because network encoded IP address is presented in big-endian format. Intel based computers encode values in little-endian form so to perform numerical operations on received IP address values you will need to convert them from big to little-endian format. By the same token, if you wish to transmit data using IP address value calculated on the local system, you will need to convert it to big-endian prior to transmission.

Namespace: SnmpSharpNet
Assembly: SnmpSharpNet (in SnmpSharpNet.dll) Version: (0.9.1)


public static uint ReverseByteOrder(
	uint val
Visual Basic
Public Shared Function ReverseByteOrder ( _
	val As UInteger _
) As UInteger
Visual C++
static unsigned int ReverseByteOrder(
	unsigned int val


Type: System..::..UInt32
Integer value to reverse

Return Value

Reversed integer value


Here is an example that demonstrates what this method does:
IpAddress test = new IpAddress(new byte[] { 10, 20, 30, 40 }); // Example IP:
UInt32 testValue = test.ToUInt32();
UInt32 reverseValue = IpAddress.ReverseByteOrder(testValue);
IpAddress newTest = new IpAddress(reverseValue);
Console.WriteLine("New IP: {0}", newTest.ToString()); // Output "New IP:"        ///

See Also