BIG Endian 和 Little Endian(small endian)模式的区别 谈到字节序的问题,必然牵涉到两大CPU派系。那就是Motorola的PowerPC系列CPU和Intel的x86系列CPU。PowerPC系列采用big endian方式存储数据,而x86系列则采用little endian方式存储数据。那么究竟什么是big endian,什么又是little endian呢?其实big endian是指低地址存放最高有效字节(MSB),而little endian则是低地址存放最低有效字节(LSB)

 判断程序运行的平台是little-endian还是big-endian

#include <stdio.h>
//判断程序运行的平台是little-endian还是big-endian
bool IsLittleEndian()
{
 int i = 1;
 char* p = (char*)&i;
 return *p;
}
int main()
{
 if(IsLittleEndian())
  printf("LittleEndian\n");
 else
  printf("BigEndian\n");
 return 0;
}

big-endian The most significant byte is on the left end of a word. 
little-endian The most significant byte is on the right end of a word. 

example:
big:   [1000]4F,[1001]52 表示4f52
little: [1000]52,[1001]4f  表示4f52

3. Converting Small endian to Big Endian using C#(long value)

Big Endian and Samll EndianCould someone tell me how to write an equivalent code in C# for the following C++ code which would give me a big endian from a small endian? Thanking you in Advance..
Big Endian and Samll Endian
Big Endian and Samll EndianFunction call 
- ProcessEndian((char*&longValue, 
Big Endian and Samll Endian     
sizeof(long));
Big Endian and Samll Endian
Big Endian and Samll Endian
void CUtility::ProcessEndian(char * pHostData, int nHostDataLength) 

相关文章: