当前位置:网站首页>Basic syntax - bit operation
Basic syntax - bit operation
2022-06-29 07:54:00 【qazw9600】
Displacement
- The data stored in memory moves left and right according to binary bits .
- Move right ( Binary data moves to the right ) The operator :>>
- Move left ( Binary data moves to the left ) The operator :<<
- Examples of use
int a = 1;
int b = a << 1; // Move left 1 position
int c = a >> 2; // Move right 2 position
C Language processing standards
- Move left : Shift and right padding
- Move right : There are two ways to do this
- Unsigned numbers are logically shifted right : Shift and left padding
- Signed numbers are arithmetically shifted right : Shift and left complement sign bit ( Positive complement 0, Negative numbers make up 1).
- Example :
unsigned int a = 0xFFFFFFFF;
int b = 0xFFFFFFFF;
printf("%x\n", a << 1);
printf("%x\n", b << 1);
printf("-----------------\n");
printf("%x\n", a >> 1);
printf("%x\n", b >> 1);
* Running results :
fffffffe
fffffffe
-----------------
7fffffff
ffffffff
Why is there only one processing method for shift left , The right shift is divided into logical right shift and arithmetic right shift
- Because left shift is often used in multiplication ( Moving one bit to the left is equivalent to multiplying by 2), Shift right is often used in division operations ( Moving one bit to the right is equivalent to dividing by 2).
- Move left ( multiply 2 After multiple of ) If the data overflows to the sign bit ( The first one on the far left ), Neither signed number nor unsigned number can be represented , Data overflow cannot be avoided , So the left shift is handled uniformly , Moving right does not cause data overflow , To ensure the right shift ( Divide 2) The correctness of the arithmetic result of , You cannot change the sign of a signed number , for example : Signed number -8 Move right 1 Bit divided by 2 The correct answer should be -4, Therefore, the processing method for signed numbers is called arithmetic shift , Unsigned numbers have no sign , Just fill in the zero by logic , So it's called logical shift right .
边栏推荐
- 【深度之眼吴恩达机器学习作业班第四期】Linear Regression with One Variable,单变量线性回归
- Wechat applet learning notes (summer vacation)
- Fluent imitates uiswitch
- Detailed explanation of top and free commands
- 1032 Sharing
- postman预处理/前置条件Pre-request
- Explanation of swing transformer theory
- TF. Repeat and stack operations of slim
- js异或混淆代码
- qtcreator设置字符集
猜你喜欢

【工控老马】基于PLC的花样喷泉设计原理详解

呕心沥血总结出来的MySQL常见错误以及解决方法(二)

4年工作经验,多线程间的5种通信方式都说不出来,你敢信?

【深度之眼吴恩达机器学习作业班第四期】逻辑回归编程实现

Kyushu cloud helps Inner Mongolia's "counting from the east to the west" project to drive the smart new ecology of the surveying and mapping industry

code::blocks代码格式化快捷键

VMware vcenter/ESXI系列漏洞总结

Vulnhub's dc7 target

Electric check code configuration

Detailed explanation of top and free commands
随机推荐
101. symmetric binary tree (recursive and iterative methods)
进程通信 - 管道
声波通讯 - 流式数据处理 - 窗口对齐
SizeBalanceTree
Appium automation test foundation ADB common commands (II)
PostgreSQL安装:The database cluster initialisation failed,stack Hbulider安装
Postman pre request
ROS当中的仿真时间以及Bag包操作
SQL 注入绕过(六)
Kingbasees v8r6 cluster maintenance case - data migration between clusters
Cv:: mat and Base64 conversion (including picture compression and decompression)
【工控老马】洗衣机PLC程序控制系统设计详解
Little white battle pointer (Part 1)
Dump (cl\alv\tree\base================================cp|set\items\for\column) when expanding node or clicking toolbar button
呕心沥血总结出来的MySQL常见错误以及解决方法(一)
【深度之眼吴恩达机器学习作业班第四期】逻辑回归编程实现
Software testing
Detailed explanation of top and free commands
jsp学习部分
Prompt during packaging: property 'sqlsessionfactory' or 'sqlsessiontemplate'‘