当前位置:网站首页>Byte order - how to judge the big end and the small end
Byte order - how to judge the big end and the small end
2022-06-12 11:29:00 【Investment paranoia】
Byte order - How to judge the big end and the small end
Big end model : The high significant bytes are stored at the low memory address . Network byte order is big end ;
The small end model : The low valid bytes are stored at the low memory address .
Natural order means big end

The principle of judgment : Define a large byte of data x, Judge storage x How about the data of the first address of .
Cast , The pointer points to the first address
Members of the consortium share a section of memory , And they all start from the first address of the memory
/********************************************************* Copyright 2022 Shengkai Liu. All rights reserved. FileName: big_endian.c Author: Shengkai Liu Date: 2022-05-30 ***********************************************************/
#include <stdio.h>
// method one
void is_big_endian()
{
printf(" Method 1 \n Cast :\n");
int a = 0x11223344;
char b = *(char *)&a;
if (b == 0x11)
{
printf(" Big end model \n");
}
else
{
printf(" The small end model \n");
}
printf("\n");
}
// method two
void is_big_endian1()
{
printf(" Method 2 \n Consortium :\n");
union u
{
int a;
char b;
}u;
u.a = 0x11223344;
if (u.b == 0x11)
{
printf(" Big end model \n");
}
else
{
printf(" The small end model \n");
}
}
int main()
{
printf("size of int: %ld\n", sizeof(int));
printf("size of char: %ld\n\n", sizeof(char));
is_big_endian();
is_big_endian1();
return 0;
}
边栏推荐
- Signal relay rxsf1-rk271018dc110v
- K59. Chapter 2 installing kubernetes V1.23 based on binary packages -- cluster deployment
- Windows10 install mysql-8.0.28-winx64
- 记录一下使用JPA时遇到的坑
- AcWing 131. The largest rectangle in the histogram (monotone stack classic application template)
- LLD monitored by ZABBIX
- 无限生长,我们都将奔赴未来 | InfoQ中国成立15周年
- 如何查看glibc版本
- manuscript手稿格式准备
- M-Arch(番外10)GD32L233评测-SPI驱动DS1302
猜你喜欢

Windows10 install mysql-8.0.28-winx64

Grid layout

^34 scope interview questions

M-arch (fanwai 12) gd32l233 evaluation -cau encryption and decryption (tease Xiaobian)

k52.第一章 基于kubeadm安装kubernetes v1.22 -- 集群部署

M-Arch(番外12)GD32L233评测-CAU加解密(捉弄下小编)

Pytorch笔记

Les humains veulent de l'argent, du pouvoir, de la beauté, de l'immortalité, du bonheur... Mais les tortues ne veulent être qu'une tortue.

【clickhouse专栏】基础数据类型说明

C# 37. textbox滚动条与多行
随机推荐
DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode
程序分析与优化 - 6 循环优化
Clj3-100alh30 residual current relay
k59.第二章 基于二进制包安装kubernetes v1.23 --集群部署
The difference between meta universe chain games and traditional games
读mysql45讲-自我总结(部分)
正则表达式 | 浅解
postman传入list
Socket programming UDP
Construction and construction of meta Universe System
Several solutions across domains
记录一下使用JPA时遇到的坑
如何查看glibc版本
Pytoch notes
Postman incoming list
Windows10 install mysql-8.0.28-winx64
C# 35. 选择默认网卡
Sendmail Dovecot 邮件服务器
arm各种交叉编译工具的区别
元宇宙链游与传统游戏的区别