当前位置:网站首页>移位运算符
移位运算符
2022-07-06 08:22:00 【踏破铁鞋无觅处,bug一写一上午】
一、左移:<<
将数字的补码相左移动,用0填充
#include <stdio.h>
int main()
{
char a = 65;
char c = a<<1;
printf("%d", c);
return 0;
}
结果为:-126
正数:65
正数原反补码相同:01000001
左移后结果:10000010 //这个是移动后的原码,需要转为补码
反码:11111101
补码:11111110
结果:-126
负数:-65
原码:11000001
反码:10111110
补码:10111111
向左移动:01111110 //该原码是一个正数,原反补相同
结果:126
二、右移:>>
将数字的补码向右移动,对于无符号数来说,用0填充,对于有符号数来说,用符号位填充。
#include <stdio.h>
int main()
{
char a = -7;
char c = a>>2;
printf("%d", c);
return 0;
}
结果位-2
负数:-7
原码:10000111
反码:11111000
补码:11111001
右移后结果:11111110 //这个是移动后的原码,需要转为补码
反码:10000001
补码:10000010
结果:-2
正数:7
正数原反补码相同:00000111
右移后结果:00000001 //这个是移动后的原码,是一个正数,原反补相同
结果:1
边栏推荐
- 灰度升级 TiDB Operator
- Pyqt5 development tips - obtain Manhattan distance between coordinates
- ESP系列引脚說明圖匯總
- Nft智能合约发行,盲盒,公开发售技术实战--合约篇
- Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
- China vanadium battery Market Research and future prospects report (2022 Edition)
- Permutation and combination function
- [MySQL] database stored procedure and storage function clearance tutorial (full version)
- 2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
- 化不掉的钟薛高,逃不出网红产品的生命周期
猜你喜欢
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
From monomer structure to microservice architecture, introduction to microservices
MySQL learning records 12jdbc operation transactions
C语言 - 位段
Hungry for 4 years + Ali for 2 years: some conclusions and Thoughts on the road of research and development
Use Alibaba icon in uniapp
IP lab, the first weekly recheck
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
3. File operation 3-with
C language custom type: struct
随机推荐
Cisp-pte practice explanation
JVM performance tuning and practical basic theory - Part 1
1202 character lookup
在 uniapp 中使用阿里图标
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Verrouillage [MySQL]
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
Nacos Development Manual
matplotlib. Widgets are easy to use
synchronized 解决共享带来的问题
Golang force buckle leetcode 1020 Number of enclaves
ESP系列引脚说明图汇总
Research and investment forecast report of citronellol industry in China (2022 Edition)
Image fusion -- challenges, opportunities and Countermeasures
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
MySQL learning record 10getting started with JDBC
Use Alibaba icon in uniapp
Golang DNS write casually
LDAP Application Section (4) Jenkins Access