gpt4 book ai didi

c - 如何将单个字节放入网络字节顺序?

转载 作者:太空宇宙 更新时间:2023-11-04 02:01:46 25 4
gpt4 key购买 nike

所以我有变量:

uint8_t version = 1;
uint8_t ttl = 1;
uint16_t payload_length =
uint32_t account_identifier = 24027;
uint32_t source_address = 0;
uint32_t destination_address = 0;
uint16_t checksum = 0;
uint16_t protocol = 1;

我想按网络字节顺序生成所有值。

我知道对 16 位值使用 htons(),对 32 位值使用 htonl()

所以我会这样做:uint32_t source_address = htonl(0);uint16_t checksum = htons(0);

我应该为 8 位值使用什么?

最佳答案

What should I use for the 8 bit values?

没有。 1 字节(8 位)值没有“字节顺序”。所以您不必担心它们(这就是为什么没有针对它们的 hton 函数)。

关于c - 如何将单个字节放入网络字节顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26475542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com