当前位置:网站首页>移位运算符
移位运算符
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
边栏推荐
- All the ArrayList knowledge you want to know is here
- Analysis of Top1 accuracy and top5 accuracy examples
- Research and investment forecast report of citronellol industry in China (2022 Edition)
- Permutation and combination function
- 化不掉的钟薛高,逃不出网红产品的生命周期
- Circular reference of ES6 module
- 【刷题】牛客网面试必刷TOP101
- [MySQL] lock
- 使用 TiDB Lightning 恢复 S3 兼容存储上的备份数据
- 704 二分查找
猜你喜欢
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
Circular reference of ES6 module
Hcip day 16
[research materials] 2021 Research Report on China's smart medical industry - Download attached
Nacos Development Manual
C语言 - 位段
Leetcode question brushing (5.28) hash table
2. File operation - write
IOT -- interpreting the four tier architecture of the Internet of things
ROS编译 调用第三方动态库(xxx.so)
随机推荐
Golang force buckle leetcode 1020 Number of enclaves
2022.02.13 - 238. Maximum number of "balloons"
[2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
使用 BR 恢复 S3 兼容存储上的备份数据
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
1202 character lookup
【MySQL】鎖
matplotlib. Widgets are easy to use
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
Online yaml to CSV tool
MySQL learning record 10getting started with JDBC
Verrouillage [MySQL]
Analysis of Top1 accuracy and top5 accuracy examples
Hill sort c language
[MySQL] database stored procedure and storage function clearance tutorial (full version)
ESP系列引脚说明图汇总
Summary of MySQL index failure scenarios
hcip--mpls
延迟初始化和密封类
使用 TiUP 升级 TiDB