当前位置:网站首页>Shift operation of complement
Shift operation of complement
2022-07-05 08:38:00 【Stay--hungry】
Usually , In the computer Signed number With Complement code stored .
Deep understanding of complement
Shift the complement left : Removed bit complement 0.
The sign bit may also change , Thus, the positive and negative numbers change .
stay When there is no sign bit change , Moving one bit to the left is equivalent to × 2 \times 2 ×2. Special , When the number is negative , This property also holds :
Suppose the number in the computer 8bit Storage :
| Complement code | Original code | Count |
|---|---|---|
| 0111 1000 | 0111 1000 | 120 |
| 1111 0000 | 1001 0000 | -16 |
| 1110 0000 | 1010 0000 | -32 |
| 1100 0000 | 1100 0000 | -64 |
| 1000 0000 | Cannot be expressed in the original code | -128 |
| 0000 0000 | 0000 0000 | 0 |
The limit value of left shift is 0.
Shift the complement right :
- Yes just Integers ( Symbol bit 0) Move right : Removed bits repair 0
- Yes negative Integers ( Symbol bit 1) Move right : Removed bits repair 1, The result is still negative
The limit value of the right shift of a positive integer is 0, The limit value of the right shift of negative integers is -1.
in fact , When it's negative , When moving right, the highest position is filled 0 Or make up 1 Depending on the rules of the compilation system .( repair 0 Of is called “ Logical shift right ”, repair 1 Of is called “ Arithmetic shift right ”.) therefore , Try not to shift negative numbers !
Be careful :
Whether arithmetic shift right or logical shift right , The result of the operation Is the original number divided by 2. For unsigned numbers , Logical shift right is adopted ( repair 0); For signed Numbers , Using arithmetic shift right . When arithmetic moves right , The number of the left complement sign bit .
边栏推荐
- [three tier architecture]
- Stm32--- systick timer
- Pytorch entry record
- MHA High available Cluster for MySQL
- Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
- Arrangement of some library files
- Matlab tips (28) fuzzy comprehensive evaluation
- STM32 --- configuration of external interrupt
- Cmder of win artifact
- Example 006: Fibonacci series
猜你喜欢
随机推荐
287. Looking for repeats - fast and slow pointer
go依赖注入--google开源库wire
【NOI模拟赛】汁树(树形DP)
STM32 virtualization environment of QEMU
STM32 --- GPIO configuration & GPIO related library functions
Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
实例009:暂停一秒输出
整形的分类:short in long longlong
【日常训练--腾讯精选50】557. 反转字符串中的单词 III
Weidongshan Internet of things learning lesson 1
PIP installation
Run menu analysis
Wheel 1:qcustomplot initialization template
轮子1:QCustomPlot初始化模板
Sword finger offer 09 Implementing queues with two stacks
Apaas platform of TOP10 abroad
Business modeling of software model | stakeholders
Five design details of linear regulator
MySQL之MHA高可用集群
696. 计数二进制子串










