zoukankan      html  css  js  c++  java
  • Big Endian and Samll Endian

    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)

    Could 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..

    Function call 
    - ProcessEndian((char*&longValue, 
         
    sizeof(long));

    void CUtility::ProcessEndian(char * pHostData, int nHostDataLength) 
    {
     
    char buffer[10];
     
    int i = 0;
     
    char* pChar = NULL;

     
    for (i=0; i<nHostDataLength; i++)
     
    {
      pChar 
    = pHostData+i;
      buffer[ i ] 
    = *(pChar);
     }


     
    for (i=0; i<nHostDataLength; i++)
     
    {
      
    *pChar = buffer[ i ];
      pChar
    --;
     }

    }
     

  • 相关阅读:
    C++开发系列-友元函数 友元类
    C++开发系列-C语言的malloc与C++的new分配空间
    C++开发系列-内联函数
    iOS开发系列-Foundation与CoreFoundation内存管理
    C开发系列-字符串
    C开发系列-数组
    列表 元组 字典
    神奇的print
    while 语句的逻辑
    <Web Crawler><Java><thread-safe queue>
  • 原文地址:https://www.cnblogs.com/cy163/p/731473.html
Copyright © 2011-2022 走看看