当前位置:网站首页>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 .
边栏推荐
- STM32 single chip microcomputer - bit band operation
- STM32 virtualization environment of QEMU
- L298N module use
- Illustration of eight classic pointer written test questions
- Stm32--- systick timer
- 实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
- Business modeling | process of software model
- MATLAB skills (28) Fuzzy Comprehensive Evaluation
- GEO数据库中搜索数据
- MATLAB小技巧(28)模糊综合评价
猜你喜欢
随机推荐
QEMU STM32 vscode debugging environment configuration
STM32 outputs 1PPS with adjustable phase
TypeScript手把手教程,简单易懂
MySQL MHA high availability cluster
UE像素流,来颗“减肥药”吧!
關於線性穩壓器的五個設計細節
Guess riddles (142)
Guess riddles (11)
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
Installation and use of libjpeg and ligpng
Guess riddles (6)
每日一题——输入一个日期,输出它是该年的第几天
Several problems to be considered and solved in the design of multi tenant architecture
暑假第一周
Infected Tree(树形dp)
【三层架构】
猜谜语啦(6)
Arrangement of some library files
Business modeling of software model | vision
99 multiplication table (C language)