byteorder.cc
来自「达内IT培训Unix C++第一天源码(共四天) 是入门Unix 下C++编程」· CC 代码 · 共 23 行
CC
23 行
#include <iostream>using namespace std;#include <netinet/in.h>void showbytes(void* addr, int size){ unsigned char* p=(unsigned char*)addr; for(int i=0; i<size; i++) cout << hex << (int)*p++ << ' '; cout << endl;}int main(){ int n=0x1; showbytes(&n, sizeof(n)); n = htonl(n); showbytes(&n, sizeof(n)); cout << "n=" << n << endl; n = ntohl(n); cout << "n=" << n << endl;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?