big and little endian

总是容易搞混big endian 和 little endian,但是找到一篇文章,其解释让人耳目一新。

文章链接:http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html

假设内存 byte-addresseable,假设我们要保存一个32bit的数据,以16进制表示为 90AB12CD。

有两种保存方式:

1. store the most significant byte in the smallest address,也就是所谓的 big endian。

2. store the least significant byte in the smallest address,也就是所谓的 little endian。

因为 the least significant byte is stored first,所以叫 little endian.

因为 the most significant byte is stored first,所以叫 big endian.

文章中介绍的内容包括但不限于这些,还介绍了 endian 的影响之类的内容。

时间: 2024-08-04 05:55:51

big and little endian的相关文章

大端和小端(big endian little endian)

一.大端和小端的问题 对于整型.长整型等数据类型,Big endian 认为第一个字节是最高位字节(按照从低地址到高地址的顺序存放数据的高位字节到低位字节):而 Little endian 则相反,它认为第一个字节是最低位字节(按照从低地址到高地址的顺序存放据的低位字节到高位字节). 例如,假设从内存地址 0x0000 开始有以下数据:  0x0000         0x0001       0x0002       0x0003  0x12            0x34          

大端和小端(Big endian and Little endian)

一.大端和小端的问题 对于整型.长整型等数据类型,Big endian 认为第一个字节是最高位字节(按照从低地址到高地址的顺序存放数据的高位字节到低位字节):而 Little endian 则相反,它认为第一个字节是最低位字节(按照从低地址到高地址的顺序存放据的低位字节到高位字节). 例如,假设从内存地址 0x0000 开始有以下数据:  0x0000         0x0001       0x0002       0x0003  0x12            0x34          

<QtEndian> - Endian Conversion Functions

The <QtEndian> header provides functions to convert between little and big endian representations of numbers. More... Functions T qFromBigEndian(const uchar * src)T qFromBigEndian(T src)T qFromLittleEndian(const uchar * src)T qFromLittleEndian(T src

彻底搞懂字符编码(unicode,mbcs,utf-8,utf-16,utf-32,big endian,little endian...)[转]

最近有一些朋友常问我一些乱码的问题,和他们交流过程中,发现这个编码的相关知识还真是杂乱不堪,不少人对一些知识理解似乎也有些偏差,网上百度, google的内容,也有不少以讹传讹,根本就是错误的(例如说 unicode编码是两个字节),各种软件让你选择编码的时候,常常是很长的一个选单,让用户不知道该如何选.基于这样的问题,我就写下我的理解吧,一方面帮助一些需要帮助的人纠正认识,一方面作为自己以后备查的资料. 1. ASCII(American Standard Code for Informati

Big Endian&#160; 和 Little Endian 模式的区别

谈到字节序的问题,必然牵涉到两大CPU派系.那就是Motorola的PowerPC系列CPU和Intel的x86系列CPU.PowerPC系列采用big endian方式存储数据,而x86系列则采用little endian方式存储数据.那么究竟什么是big endian,什么又是little endian呢? 其实big endian是指低地址存放最高有效字节(MSB),而little endian则是低地址存放最低有效字节(LSB). 用文字说明可能比较抽象,下面用图像加以说明.比如数字0x

理解字节序 [Understanding Big and Little Endian Byte Order]

原文地址 (本文对于字节序讲解的很清楚,容易理解.) Problems with byte order are frustrating, and I want to spare you the grief I experienced. Here's the key: Problem: Computers speak different languages, like people. Some write data "left-to-right" and others "rig

[C/C++]_[初级]_[判断大小端序Little Endian Order]

场景: 1. 在读取硬盘数据和媒体数据时,需要根据读取的数据进行大小端序的转换,以正确识别数据.其中一个处理就是首先要判断cpu支持的大小端序情况才能转换. 2. Little Endian Order: 低地址存低位(整数的高低位)的数据. test.cpp #include <stdio.h> #include <iostream> using namespace std; //1.方法1,通过判断int的低位是否存储了数值. int IsLittleEndian1() { i

大端字节(Big endian)与小端字节(Little endian)

本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/32752587 常见的80x86 CPU是先存放小值,再存放大值.这是小端字节(Little endian)序列. 而数字在互联网上传输的时候,是大端字节序列(Big endian).所以,网络编程里有一个api是htons(),用来将主机字节顺序转化成为网络字节顺序. 常见的CPU平台如下: 处理器 操作系统 字节顺序 Alpha 全部 little

〖Linux〗使用sed命令修改小端(little endian)存储的数据

1 #!/bin/bash - 2 #=============================================================================== 3 # 4 # FILE: hex_change.sh 5 # 6 # USAGE: ./hex_change.sh 7 # 8 # DESCRIPTION: 9 # 10 # OPTIONS: --- 11 # REQUIREMENTS: --- 12 # BUGS: --- 13 # NOTES:

判断CPU 是小端存储(Little endian)还是大端存储(Big endian)模式

第一个版本: //return true in big-endian machines bool check_big_endian1() { int a = 0; int *p = &a; *(char *)p = 1; return a != 1; } 采用union的第二个版本: //return true in big-endian machines bool check_big_endian2() { union{ int a; char b; }var;//sizeof(var)=4