网络字节顺序和字节顺序问题 [英] Network byte order and endianness issues

查看:184
本文介绍了网络字节顺序和字节顺序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上看到网络的标准字节顺序是大端,也称为网络字节顺序。在网络上传输数据之前,首先将数据转换为网络字节顺序(big endian)。

I read on internet that standard byte order for networks is big endian, also known as network byte order. Before transferring data on network, data is first converted to network byte order (big endian).


  1. 但是任何一个请让我知道谁

  2. 代码开发人员是否真的担心这个字节顺序?如果是的,你能让我知道我们需要关心的例子(在C,C ++的情况下)。


推荐答案

在C和C ++中,您必须担心低级网络代码中的字节序。通常,序列化和反序列化代码将调用调整字节序的函数或宏,即在使用多字节数据类型时,在小端字节序机器上进行反转,不对大字节序机器进行任何操作。

In C and C++, you will have to worry about endianness in low level network code. Typically the serialization and deserialization code will call a function or macro that adjusts the endianness - reversing it on little endian machines, doing nothing on big endian machines - when working with multibyte data types.

这篇关于网络字节顺序和字节顺序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆