what is the difference between little-endian and big-endian.
2009-03-14 10:59
567 查看
老掉牙的问题,不过有时候往往因为这个问题而找不到问题的根源所在,最近就因为大小端问题害我浪费了半天时间,所以写下小记让自己多care一下这些细节问题。
1. 概念描述
little-endian 高字节在存储在高地址处,低字节存储在低地址处;
big-endian 高字节在存储在低地址处,低字节存储在高地址处。
简单的例子,对于一个32位的数0x88776655,保存在地址0x00000000处,对应的大小端存储格式如下:
big-endian little-endian
0x00000000 0x88 0x55
0x00000001 0x77 0x66
0x00000002 0x66 0x77
0x00000003 0x55 0x88
2. 判断所用的处理器类型
x86系列处理器都是用little-endian格式,PowerPC则使用big_endian格式,对于一些不太明确的处理器类型可以写个程序加以判别:
typedef union
{
unsigned char b1;
unsigned int t1;
} endien_t;
bool IsLittleEnd(void)
{
endien_t t;
t.b1 = 0x01;
return (t.t1&0xff);
}
1. 概念描述
little-endian 高字节在存储在高地址处,低字节存储在低地址处;
big-endian 高字节在存储在低地址处,低字节存储在高地址处。
简单的例子,对于一个32位的数0x88776655,保存在地址0x00000000处,对应的大小端存储格式如下:
big-endian little-endian
0x00000000 0x88 0x55
0x00000001 0x77 0x66
0x00000002 0x66 0x77
0x00000003 0x55 0x88
2. 判断所用的处理器类型
x86系列处理器都是用little-endian格式,PowerPC则使用big_endian格式,对于一些不太明确的处理器类型可以写个程序加以判别:
typedef union
{
unsigned char b1;
unsigned int t1;
} endien_t;
bool IsLittleEnd(void)
{
endien_t t;
t.b1 = 0x01;
return (t.t1&0xff);
}
相关文章推荐
- The Differences between Little-Endian and Big-Endian
- OpenStack: What is the difference between Block storage and Object storage?Also, In what way they ar
- What is the difference between char s[] and char *s?
- What is the basic difference between NSTimer, NSTask, NSThread and NSRunloop ?
- What is the difference between SVD and matrix factorization in context of recommendation engine?
- what is the difference between json and javascript object.
- What is the difference between SLC and MLC?
- What is the difference between Enumeration and Iterator ?
- What is the difference between .NET 1.1,2.0,3.0,3.5 and 4.0
- What is the difference between call and apply?(关键词:call/apply/invoke)
- What is the difference between AWT and SWT?
- overload与override的区别 What is the difference between overload and override
- What is the difference between "green" threads and "native" threads?
- What is the difference between arguments and parameters?
- 文科和理科的区别(What is the difference between science and engineering)?
- What is the difference between Facade and Gateway design patterns?
- whats is the difference between train, validation and test set, in neural networks?
- Q: What is the difference between protocol stacks and profiles?蓝牙协议栈和profile的区别
- What is the difference between a binary tree, a binary search tree, a B tree and a B+ tree?
- What is the difference between a Session and a Cookie?