Originally Posted by
tabstop
Well, hopefully the library knows what the host-order is; and network order is well defined. So the function "knows" either to flip (as above), or do nothing....
How can it possibly know the difference between Big Endian and Little Endian? Just by looking at a number there's no way to know.
Is 0xFE1265CD02 Big Endian or Little Endian? There's no special bit (like a signed number) that says this is Big Endian...
Code:
#include <iostream>
#include <winsock2.h>
using namespace std;
int main()
{
unsigned long num = 1234567890;
cout << num << endl;
num = htonl( num );
cout << num << endl;
num = htonl( num );
cout << num << endl;
return 0;
}
Output:
Code:
1234567890
3523384905
1234567890