zoukankan      html  css  js  c++  java
  • 判断big endian和little endian的方法

    Big endian machine: It thinks the first byte it reads is the biggest.

    Little endian machine: It thinks the first byte it reads is the littlest.

    #include <stdio.h>

    int main(int argc, char **argv)
    {
            union {
              short  s;
          char   c[sizeof(short)];
        } un;

            un.s = 0x0102;
            if (sizeof(short) == 2) {
                    if (un.c[0] == 1 && un.c[1] == 2)
                            printf("big-endian\n");
                    else if (un.c[0] == 2 && un.c[1] == 1)
                            printf("little-endian\n");
                    else
                            printf("unknown\n");
            } else
                    printf("sizeof(short) = %d\n", sizeof(short));

            exit(0);
    }

    总结一下:big endian是适合大家的阅读顺序,little endian则相反。

  • 相关阅读:
    网络流 KM dinic
    网络流 增广路 回退
    树链剖分
    线段树区间更新 lazy
    全排列
    各种蕴含算法思想的DP
    各种蕴含算法思想的DP
    Strassen矩阵乘法之思考
    [0,x)的随机数
    hdu1331 按着题目的公式直接写
  • 原文地址:https://www.cnblogs.com/shanks/p/1502368.html
Copyright © 2011-2022 走看看