Jeff said:
I'm confused by that statement. 0x3264A8C0 has 192 (C0) as the LSB, which
would suggest to me that the integer is in little-endian format.
Why would it do that? The IP address "192.168.100.50" isn't an integer
format to start with. You can't tell from that string whether the IP
address is represented as little- or big-endian.
As far as the statement I made goes, my point is that the
string-formatted integer "3264A8C0" parsed naturally by the
Int32.Parse() method winds up being stored as a 32-bit integer with the
value 0x3264A8C0. Again, no endian-ness can be inferred at this point.
But, we know that in .NET, integers are little-endian, while the
IPAddress(Int64) constructor expects big-endian where the LSB is the
last octet of the IP address. That is, the IPAddress(Int64) method
treats the passed in data as if it were big-endian, and uses the LSB of
the data as the least-significant octet of the IP address.
I admit that the statement I made is a bit confusing, because I am using
"endian" to describe data that doesn't really need to be interpreted as
having endian-ness. "Endian" really only applies to a sequence of
bytes; once that sequence of bytes is stored in a larger data type, such
as an Int32, it has no endian-ness until you want to write it back out
to some sequence of bytes.
In terms of .NET, this "larger data type" is an Int32 variable; at the
CPU level, it would be a register. Either way, there's no endian-ness
per se when the data is stored in that way. So technically my statement
isn't accurate.
But my point is that if one _does_ take a little-endian integer and
treat it as a sequence of bytes, the IPAddress(Int64) constructor then
turns around and interprets that sequence of bytes as if it were
big-endian (i.e. it reverses the bytes), _and_ it extracts the
least-significant octet of the IP address from the least-significant
byte of the integer.
Unfortunately, even that statement isn't quite precise, because the
IPAddress(Int64) constructor apparently also ignores leading zeroes in
the integer.
The bottom line here is that the OP need not reverse the bytes before
passing the parsed integer to the IPAddress(Int64) constructor.
Pete