当前位置:网站首页>Integer promotion and size side byte order
Integer promotion and size side byte order
2022-06-28 06:13:00 【Huahai ovo】
With an integer type number 1 For example His binary representation is
000000000000000000000000000000001;
And in computer storage His data is stored in hexadecimal , namely
0x 00 00 00 01
From left to right is the high to low order of the data , And the memory in the computer also corresponds to high memory to low memory , Then there is the concept of byte order at the big and small ends
Big endian byte order : It means that the high bit of data is stored in the low address , The low order of the data is stored at the high address
Small endian byte order : The high bit of data is stored at the high address , The lower order of the data is stored at the lower address
So how do we judge what we use vs When storing data, do you use large end byte order or small end byte order , We can create one char The pointer of type points to the number of integer type 1, because char* Only one byte can be accessed from high to low , So we can pass char A pointer to access 1 The first byte of , Let's see what he is 0 still 1, So as to determine the size of its storage end
The code is as follows :
char*p=NULL;// Initialization pointer
int a=1;
p=&a;//p Point to a One byte in
if(*p)
printf(" It's the big end ");
else
printf(" It's the small end ");
// have a look p Access after application a Middle specific byte
So what is integer lift
Let's look at a piece of code
int main(){
char a=-1;
signed char b=-1;
unsigned char c=-1;
printf("%d %d %d",a,b,c);that a,b,c What are the results of ;
We know , Numbers are stored in memory in the form of complements -1 The original code of is
10000000 00000000 000000000 00000001
In addition to the sign bit, that is, the highest bit, the bit is reversed Get the inverse ;
11111111 11111111 11111111 11111110;
Add one to the inverse code to get the complement
11111111 11111111 11111111 11111111;
However char Type can only store one byte So truncation happens Take the lower byte namely
11111111
Use a Make a calculation or use %d Output a The integer will be promoted to look at the highest bit of a byte ; if 1 Then the preceding three bits are all 1jiayi Bytes of ; The highest bit is 0 Then fill in the front 0
For now 11111111 The highest bit is 1 Therefore, it is
11111111 11111111 11111111 11111111 For the complement
Add one to it to get the source code and output it The result is -1;
Empathy b and a Also, integer promotion will occur ;char Types are signed by default signed char;
and unsigned char It won't be like this , Because it is set to unsigned character type when defining So it thinks that the highest bit to be intercepted is not a sign bit but a number bit Therefore, all zeros are filled in front during integer lifting
The box %d Output c It will be promoted to
00000000 00000000 00000000 11111111
The highest sign bit is zero So it's a positive number The complement of positive numbers is the same So the direct output is 256
What is the significance of integer upgrade

边栏推荐
- 链表(一)——移除链表元素
- Yygh-7-user management
- 从0配置redis
- 借助nz-pagination中的let-total解析ng-template
- What is the e-commerce conversion rate so abstract?
- Camx架构开UMD、KMD log以及dump图的方式
- Example of MVVM framework based on kotlin+jetpack
- death_satan/hyperf-validate
- Alibaba cloud SMS service (Complete Guide), SMS sending function implementation.
- Apple MDM Bypass 免越狱绕过MDM配置锁 免费
猜你喜欢

MySQL(一)——安装

Xcode13.3.1 项目执行pod install后报错

Linux Mysql 实现root用户不用密码登录
![Taobao seo training video course [22 lectures]](/img/81/21e844542b35010760d061abe905e9.jpg)
Taobao seo training video course [22 lectures]
![[staff] arpeggio mark](/img/45/0ee0089b947b467344b247839893d7.jpg)
[staff] arpeggio mark

Paper recommendation: efficientnetv2 - get smaller models and faster training speed through NAS, scaling and fused mbconv

YYGH-6-微信登录

Yygh-6-wechat login

YYGH-BUG-02

JDBC learning (I) -- implementing simple CRUD operations
随机推荐
JSP
Example of MVVM framework based on kotlin+jetpack
PKG package node project (express)
Prime mover × Cloud primordial is making sound, reducing cost and increasing efficiency lecture hall
Enum
JQ picture amplifier
death_ satan/hyperf-validate
Development trend of mobile advertising: Leveraging stock and fine marketing
easyui下拉框选中触发事件
Camx架构开UMD、KMD log以及dump图的方式
Alibaba cloud SMS service (Complete Guide), SMS sending function implementation.
MySQL (II) - basic operation
Linux Mysql 实现root用户不用密码登录
mac下安装多个版本php并且进行管理
链表(二)——设计链表
高质量国产立体声编解码器CJC8988,Pin to Pin替代WM8988
Select trigger event from easyUI drop-down box
OpenSCAP 简介
Ethereum Classic的难度计算|猿创征文
ROS rviz_ Satellite function package visualizes GNSS track and uses satellite map