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
    --;
     }

    }
     

  • 相关阅读:
    界面间传值
    消息通知中心
    ios外部链接或者app唤起自己的app
    iOS跳转第三方应用举例一号店和京东
    ios 传递JSON串过去 前面多了个等号
    react-native 配置 在mac 上找不到.npmrc
    webView 获取内容高度不准确的原因是因为你设置了某个属性
    WKWebView 加载本地HTML随笔
    关于attibutedText输出中文字符后的英文和数字进行分开解析的问题
    iOS 企业包碰到的问题
  • 原文地址:https://www.cnblogs.com/cy163/p/731473.html
Copyright © 2011-2022 走看看