当前位置:网站首页>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 .
边栏推荐
- 猜谜语啦(8)
- STM32 single chip microcomputer - external interrupt
- STM32 lights up the 1.8-inch screen under Arduino IDE
- 猜谜语啦(142)
- 696. Count binary substring
- MHA High available Cluster for MySQL
- Guess riddles (6)
- Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
- Wheel 1:qcustomplot initialization template
- Business modeling of software model | object modeling
猜你喜欢
L298N module use
STM32 single chip microcomputer - external interrupt
Meizu Bluetooth remote control temperature and humidity access homeassistant
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
Business modeling of software model | stakeholders
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
Sword finger offer 05 Replace spaces
猜谜语啦(8)
Keil use details -- magic wand
随机推荐
实例007:copy 将一个列表的数据复制到另一个列表中。
Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?
猜谜语啦(8)
MATLAB skills (28) Fuzzy Comprehensive Evaluation
Daily question - input a date and output the day of the year
猜谜语啦(2)
關於線性穩壓器的五個設計細節
Array integration initialization (C language)
2020-05-21
Business modeling of software model | stakeholders
Illustration of eight classic pointer written test questions
How can fresh students write resumes to attract HR and interviewers
STM32 lights up the 1.8-inch screen under Arduino IDE
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
MySQL之MHA高可用集群
An enterprise information integration system
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
EA introduction notes
2022.7.4-----leetcode. one thousand and two hundred
QEMU STM32 vscode debugging environment configuration