fork download
  1. #ifdef _WIN32
  2. #pragma comment(lib, "ws2_32.lib")
  3. #include <WinSock2.h>
  4. #else
  5. #include <arpa/inet.h>
  6. #endif
  7.  
  8. #include <stdio.h>
  9.  
  10. int main()
  11. {
  12. char str1[2] = { 0x00, 0x06 };
  13. char str2[2] = { 0x04, 0xD2 };
  14. int result;
  15.  
  16. result = ntohs(*(u_short*)str1);
  17. printf("%d\n", result);
  18. result = ntohs(*(u_short*)str2);
  19. printf("%d\n", result);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.02s 1720KB
stdin
Standard input is empty
stdout
6
1234