ÇEndian的转换:由点点滴滴 [英] C Endian Conversion : bit by bit

查看:135
本文介绍了ÇEndian的转换:由点点滴滴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特殊的无符号长(32位),我需要它的字节序的点点滴滴转换 - 几件事情都一起smooshed我再长presents成一片二进制

I have a special unsigned long (32 bits) and I need to convert the endianness of it bit by bit - my long represents several things all smooshed together into one piece of binary.

我该怎么办呢?

推荐答案

字节序就是一个字层次的概念,其中的字节要么先保存最显著字节(大端)或最低显著字节在前(小端)。通过网络传输数据通常是大端(所谓网络字节顺序)。存储在存储器中的计算机上的数据可以以任何顺序,与小端是最常见的给定的Intel x86架构的prevalence。尽管大多数的计算机体系结构是大端,在x86是无处不在,你会经常看到在内存小尾数数据。

Endianness is a word-level concept where the bytes are either stored most-significant byte first (big endian) or least-significant byte first (little endian). Data transferred over a network is typically big endian (so-called network byte order). Data stored in memory on a machine can be in either order, with little endian being the most common given the prevalence of the Intel x86 architecture. Even though most computer architectures are big endian, the x86 is so ubiquitous that you'll most often see little endian data in memory.

总之,一切的一点是,字节顺序是仅适用于在字节级,而不是位水平非常具体的概念。如果 ntohs和() ntohl() htons() htonl()不要做你想做你与处理不ENDIANNESS本身然后什么。

Anyhow, the point of all that is that endianness is a very specific concept that only applies at the byte level, not the bit level. If ntohs(), ntohl(), htons(), and htonl() don't do what you want then what you're dealing with isn't endianness per se.

如果你需要扭转你的unsigned long类型的各个位或做任何事情复杂化这样的,请张贴关于正是你需要做的更多的信息。

If you need to reverse the individual bits of your unsigned long or do anything else complicated like that, please post more information about what exactly you need to do.

这篇关于ÇEndian的转换:由点点滴滴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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