zoukankan      html  css  js  c++  java
  • write a macro to judge big endian or little endian

    Big endian means the most significant byte stores first in memory. int a=0x01020304, if the cpu is big endian, data are store 01 02 03 04 in memory in increasing address.

    Below is a simple code to make the judgement.

    //execute the following cmd on the command line,
    //Judge the output, 1 for little endian, 0 for big endian
    //echo -n I | od -o | head -n 1 | cut -f2 -d " " | cut -c 6
    //1

    #include <stdio.h>
    #define IS_BIG_ENDIAN (*(short*)"1" == (short)1)

    int main()
    {
    if (IS_BIG_ENDIAN)
    printf("the cpu is big endian ");
    else
    printf("the cpu is small endian ");
    }

  • 相关阅读:
    C# 小算法1
    函数 y=x^x的分析
    随机数
    对拍
    Cube Stack
    Permutation
    一笔画问题
    康托展开&&康托逆展开
    待完成
    小错误 17/8/10
  • 原文地址:https://www.cnblogs.com/Torstan/p/3180892.html
Copyright © 2011-2022 走看看