当前位置:网站首页>移位运算符
移位运算符
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
边栏推荐
- [2022 Guangdong saim] Lagrange interpolation (multivariate function extreme value divide and conquer NTT)
- 704 二分查找
- PLT in Matplotlib tight_ layout()
- Use Alibaba icon in uniapp
- C语言 - 位段
- [cloud native] teach you how to build ferry open source work order system
- Deep learning: derivation of shallow neural networks and deep neural networks
- Online yaml to CSV tool
- JVM performance tuning and practical basic theory - Part 1
- Mobile Test Engineer occupation yyds dry goods inventory
猜你喜欢
Zhong Xuegao, who cannot be melted, cannot escape the life cycle of online celebrity products
[research materials] 2021 China online high growth white paper - Download attached
matplotlib. Widgets are easy to use
ESP系列引脚說明圖匯總
From monomer structure to microservice architecture, introduction to microservices
2022.02.13 - NC003. Design LRU cache structure
synchronized 解决共享带来的问题
Hungry for 4 years + Ali for 2 years: some conclusions and Thoughts on the road of research and development
hcip--mpls
[brush questions] top101 must be brushed in the interview of niuke.com
随机推荐
从 SQL 文件迁移数据到 TiDB
使用 Dumpling 备份 TiDB 集群数据到兼容 S3 的存储
logback1.3. X configuration details and Practice
sys. argv
Golang DNS 随便写写
LDAP Application Section (4) Jenkins Access
[2022 Guangdong saim] Lagrange interpolation (multivariate function extreme value divide and conquer NTT)
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
指针和数组笔试题解析
C language custom type: struct
你想知道的ArrayList知识都在这
灰度升级 TiDB Operator
[research materials] 2021 Research Report on China's smart medical industry - Download attached
1204 character deletion operation (2)
China vanadium battery Market Research and future prospects report (2022 Edition)
Upgrade tidb operator
Introduction to number theory (greatest common divisor, prime sieve, inverse element)
Is it safe to open an account in Zheshang futures?
Migrate data from CSV files to tidb
LDAP应用篇(4)Jenkins接入