zoukankan      html  css  js  c++  java
  • 判断大端小端模式

    代码如下:

    big_little_endian.c

     1 #include <stdio.h>
     2 
     3 #define BIG_ENDIAN     1
     4 #define LITTEL_ENDIAN  0
     5 
     6 int big_littel_endian(void)
     7 {
     8     union num
     9     {
    10         int a;
    11         char b[4];
    12     }c;
    13     
    14     c.a = 0x1234;
    15     
    16     if(c.b[0] == 0x34)
    17     {
    18         return LITTEL_ENDIAN;
    19     }
    20     else
    21     {
    22         return BIG_ENDIAN;
    23     }
    24     
    25 }
    26 
    27 int main()
    28 {
    29     int cpu;
    30     
    31     cpu = big_littel_endian();
    32     
    33     if(cpu == LITTEL_ENDIAN)
    34         printf("cpu is Little_endian.
    ");
    35     else
    36         printf("cpu is Big_endian.
    ");
    37 }

    在Linux下编译:

    gcc -o big_little_endian big_little_endian.c

    运行:

    ./big_little_endian

    输出结果:

    cpu is Little_endian.

  • 相关阅读:
    登录界面
    动手动脑
    关于二进制
    Java考试
    D
    威尔逊定理 k!%p
    11.46.2020质检
    最长上升序列输出方案
    问题 G: 汽车的最终位置
    奶牛大会(二分)
  • 原文地址:https://www.cnblogs.com/geekham/p/4225561.html
Copyright © 2011-2022 走看看