当前位置:网站首页>【网络协议】| 【01】网络字节序大端、小端
【网络协议】| 【01】网络字节序大端、小端
2022-06-09 02:15:00 【Jxiepc】
文章目录
1、字节序
为计算机内存中数字数据的字节顺序或序列,也可用于描述比特在通信信道上传输的顺序;
- big-endian(大端):将字的最高有效字节存储在最小的内存地址,而最低有效字节存储在最大的内存地址;
- little-endian(小端):将最低有效字节存储在最小地址;
big-endian是网络协议中最主要的顺序;
little-endian是处理器架构及其相关内存的主要顺序;
字节序存储的重要性

大端小端转换
template<class T>
typename std::enable_if<sizeof(T) == sizeof(uint64_t), T>::type
byteswap(T val) {
return (T)bswap_64((uint64_t)val);
}
template<class T>
typename std::enable_if<sizeof(T) == sizeof(uint32_t), T>::type
byteswap(T val) {
return (T)bswap_32((uint32_t)val);
}
template<class T>
typename std::enable_if<sizeof(T) == sizeof(uint16_t), T>::type
byteswap(T val) {
return (T)bswap_16((uint16_t)val);
}
void test() {
uint64_t x = 0x12345678;
printf("%X\n", x);
printf("%lx\n", byteswap(x));
}
边栏推荐
- The 600 yuan Tiktok cloud bouncing Di live studio project is the source code of the tuyere project that rewards the income from live broadcasting
- 不容错过|额度管理与应用-银行信用卡行为评分篇(实操见)
- SEC asset management - swebui open source application solution
- C语言图书信息管理系统
- The high-end is weak. Can Yanghe still keep the third place in the industry?
- FRP construction
- Custom paging
- A practical comprehensive navigation website
- Official account mall system makes e-commerce easier!
- Suppress status error LNK1104 failed to open the file "boost_thread-vc142-mt-gd-x64-1\u 79.lib"
猜你喜欢

21、ADS使用记录之E类功放设计(中)

MySQL starts the binlog log to recover the erroneously deleted tables, data and MySQL database

Why the volatile keyword is required for double check locks

接口测试系列——转转交易业务场景接口测试实践

Shell loop for while (IV)

Indonesia widya robotics and Huawei cloud make the safety of construction sites visible

27 | discussion on high water level and leader epoch

How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)

NFT chain game system development | defi+nft technology construction

Swift GCD DispatchGroup Notify wait DispatchSourceTimer Monitor system file Two apps communicate
随机推荐
Blue Bridge Cup_ N-ary linear equations_ Gauss elimination
[FBCTF2019]RCEService
编写循环何条件任务
21、ADS使用记录之E类功放设计(中)
Kubernetes scheduling framework extension point
二叉树链式结构
662. maximum width of binary tree -bfs
NSSCTF prize_ p5
Write cycle condition task
【Unity中的MVC思想——使用MVC制作UI逻辑】
Cve - 2022 - 30525 Replay of vulnerability
[high level knowledge] epoll implementation principle of user mode protocol stack
[Q & A] time synchronization mechanism in time sensitive network-802.1as
String 3-387. First unique character in string
Diffusion model has been very popular in the field of image generation recently. How do you think its popularity has begun to surpass Gan?
How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)
GCD Locks Dead cycle SpinLock synchronized
Blue Bridge Cup_ Multiple problem_ stack_ Remainder
[SUCTF 2019]EasyWeb
Zhihu hot discussion: at the age of 35, do you want to escape Beijing, Shanghai and Guangzhou?