当前位置:网站首页>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 .
边栏推荐
- [NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
- Run菜单解析
- Program error record 1:valueerror: invalid literal for int() with base 10: '2.3‘
- 关于线性稳压器的五个设计细节
- An enterprise information integration system
- Guess riddles (7)
- The first week of summer vacation
- 【三层架构及JDBC总结】
- Business modeling | process of software model
- 猜谜语啦(8)
猜你喜欢
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
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?
Guess riddles (10)
猜谜语啦(4)
Guess riddles (8)
How to write cover letter?
Xrosstools tool installation for X-Series
Lori remote control LEGO motor
STM32 lights up the 1.8-inch screen under Arduino IDE
Example 006: Fibonacci series
随机推荐
Tips 1: Web video playback code
One question per day - replace spaces
Program error record 1:valueerror: invalid literal for int() with base 10: '2.3‘
Low code platform | apaas platform construction analysis
Array integration initialization (C language)
Google sitemap files for rails Projects - Google sitemap files for rails projects
Guess riddles (9)
每日一题——替换空格
猜谜语啦(4)
Count the number of inputs (C language)
How to write cover letter?
Arduino operation stm32
U8g2 drawing
STM32 single chip microcomputer -- volatile keyword
2022.7.4-----leetcode.1200
猜谜语啦(6)
STM32 single chip microcomputer - external interrupt
關於線性穩壓器的五個設計細節
Esphone Feixun DC1 soft change access homeassstant
Xrosstools tool installation for X-Series