fork download
  1. #include <iostream>
  2. #include <netinet/in.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. const uint8_t bytes[4] = {0x00, 0x01, 0x02, 0x03};
  8. uint32_t n = *(uint32_t*)(void*)bytes;
  9. cout << hex << n << endl;
  10.  
  11. auto i = htonl(n);
  12. cout << hex << i << endl;
  13.  
  14. i = ntohl(i);
  15. cout << hex << i << endl;
  16.  
  17. i = ntohl(0x93000000);
  18. cout << i << endl;
  19.  
  20. i = ntohl(0x8d000000);
  21. cout << i << endl;
  22.  
  23. i = ntohl(0x67000000);
  24. cout << i << endl;
  25.  
  26. i = ntohl(0x41000007);
  27. cout << i << endl;
  28.  
  29. i = ntohl(0x0000005f);
  30. cout << i << endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
3020100
10203
3020100
93
8d
67
7000041
5f000000