zoukankan      html  css  js  c++  java
  • 【工作笔记】大端与小端

    定义

    大端    一个Word中的高位的Byte放在内存中这个Word区域的低地址处。   
    小端   一个Word中的低位的Byte放在内存中这个Word区域的低地址处。

    判断CPU是大端或小端

     1 #include <stdio.h>
     2 
     3 int main()
     4 {
     5      union w
     6     {
     7      int a;  //4 bytes
     8      char b; //1 byte
     9      } c;
    10 
    11      c.a=1;
    12 
    13      if (c.b==1)
    14           printf("It is Little_endian!\n");
    15       else
    16           printf("It is Big_endian!\n");
    17 
    18       return 1;
    19 }

    说明:
     在c中,联合体(共用体)的数据成员都是从低地址开始存放。
     若是小端模式,由低地址到高地址c.a存放为0x01 00 00 00c.b被赋值为0x01

      ————————————————————————————

       地址 0x00000000 0x00000001 0x00000002 0x00000003

       c.a  01         00         00         00

       c.b  01         00        

      ————————————————————————————  
     若是大端模式,由低地址到高地址c.a存放为0x00 00 00 01c.b被赋值为0x0

      ————————————————————————————

       地址 0x00000000 0x00000001 0x00000002 0x00000003

       c.a  00         00         00         01

       c.b  00         00                 

      ————————————————————————————  

    TCP/IP协议栈用的是大端。

     

     

  • 相关阅读:
    test
    4css
    3css
    2css
    5html
    1css
    4html
    3html
    2html
    1.3 tensorflow2.0 常用函数
  • 原文地址:https://www.cnblogs.com/zhiqli/p/3120526.html
Copyright © 2011-2022 走看看