当前位置:网站首页>Shift operator (detailed)
Shift operator (detailed)
2022-06-30 14:49:00 【I would, I think】
Shift Operators
Move left (<<)
Positive numbers : In binary form , Move all the numbers to the left by the corresponding digits , High removal , Low vacancy filling 0
for example 12<<2=48
- 12 Corresponding binary 0000 1100
- Move two bits to the left to become 0011 0000
- Convert to decimal 2^4+2^5=16+32=48
negative : for example -12<<2=-48
- 12 Corresponding binary 0000 1100, be -12 The corresponding original code is 1000 1100
- Original code ——> Inverse code , The sign bits remain the same , The rest is reversed , become 1111 0011
- Inverse code ——> Complement code , Counter code plus 1, Has become a 1111 0100
- therefore -12 The corresponding binary is 1111 0100( Complement code )
- Move two places to the left , Low complement 0, become 1101 0000
- Complement code ——> Inverse code , Subtract one from the corresponding complement , become 1100 1111
- Inverse code ——> Original code , The sign bits remain the same , The rest is reversed 1011 0000
- Convert binary to decimal ,2^4+2^5=16+32=48, The highest position is 1, Then for -48

- The first ① Situated 0 Not enough to reduce , towards ② Loan processing “1” When “2”,2-1=1
- Because the first ② Situated 0 Borrowed “1”, said “-1”, but ② The place itself does not , And to ③ Loan processing “1” When “2”,2-1=1
- Because the first ③ Situated 0 Borrowed “1”, said “-1”, But not enough , And to ④ Loan processing “1” When “2”,2-1=1
- The first ④ Situated 0 Borrowed “1”, said “-1”, But not enough , And to ⑤ Loan processing “1” When “2”,2-1=1
- The first ⑤ Situated 1 Borrowed , be 1-1=0
Move right (>>): Move all the numbers to the right by the corresponding shift digits in binary form , Move out low ( Abandon ), The empty bits in the high order are complemented by positive numbers 0, Negative numbers make up 1
Positive numbers :20>>2=5
- take 20 Convert to binary to 0001 0100
- Move two bits to the right to become 0000 0101
- Convert binary to decimal 2^0+2^2=5
negative :-20>>2=-5
- 20 Corresponding binary 0001 0100,-20 Then the corresponding original code is 1001 0100
- Original code ——> Inverse code , The sign bits remain the same , The rest is reversed , become 1110 1011
- Inverse code ——> Complement code , Counter code plus 1, Has become a 1110 1100
- therefore -20 The corresponding binary is 1110 1100( Complement code )
- Move two places to the right , High compensation 1, become 1111 1011
- Complement code ——> Inverse code , Subtract one from the corresponding complement , become 1111 1010
- Inverse code ——> Original code , The sign bits remain the same , The rest is reversed 1000 0101
- Convert binary to decimal ,, The highest position is 1, Then for 2^0+2^2=5, The highest bit is 1, Then for -5
Unsigned operator (>>>)
Move all numbers in binary form to the right by the corresponding number of digits , Move out low ( Abandon ), Fill in the high vacancy . For positive numbers and signed right shift (>>) identical , But it's different for negative numbers .
Positive numbers :15>>>2=3
- Convert to binary 0000 1111
- Move two places to the right , High compensation 0, become 0000 0011
- Convert binary to decimal , become 2^0+2^1=3
negative :-15>>>2
- 15 Convert to binary 0000 0000 0000 0000 00000 0000 0000 1111,
-15 Corresponding to the original code 1000 0000 0000 0000 00000 0000 0000 1111
- Original code ——> Inverse code , The sign bits remain the same , The rest is reversed ,1111 1111 1111 1111 1111 1111 1111 0000
- Inverse code ——> Complement code , Counter code plus 1, become 1111 1111 1111 1111 1111 1111 1111 0001
- therefore -15 The binary of is 1111 1111 1111 1111 1111 1111 1111 0001( Complement code )
- Move two places to the right , High compensation 0, become 0011 1111 1111 1111 1111 1111 1111 1100
- Complement code ——> Inverse code , Complement subtraction 1,0011 1111 1111 1111 1111 1111 1111 1011
- Inverse code ——> Original code , The sign bits remain the same , The rest is reversed , become
0100 0000 0000 0000 00000 0000 0000 0100
- Convert binary to decimal ,2^2+2^30=1073741828
Because the sign bits of negative numbers ( highest ) by 1, The unsigned right shift should be filled in the highest position 0, therefore 32 Bit binary must be written completely . Move right with symbol (>>), The high bit is the sign bit of complement , front 24 All places are 1( The number in the example is small ,8 Bits are enough to show ; If the number is large , want 16 Words that can only be expressed by bits , That's before 16 All places are 1), Omitting does not affect the calculation ; But this is a special case , The complement bit is different from the sign bit .
边栏推荐
- 數據恢複軟件EasyRecovery15下載
- JS time conversion standard format, timestamp conversion standard format
- Searching for single element in dichotomy
- Why is the resolution of the image generated by PHP GD library 96? How to change it to 72
- [buuctf] [actf2020 freshman competition]exec1
- DefCamp Capture the Flag (D-CTF) 2021-22 web
- One dimensional and two dimensional array addresses
- Notepad regular delete the line of the keyword
- Logiciel de récupération de données easyrecovery15 téléchargement
- The JSON data returned from the control layer to JS has a "\" translator. How to remove it
猜你喜欢

day02

August 24, 2021 deque queue and stack
![[geek challenge 2019] PHP problem solving record](/img/bf/038082e8ee1c91eaf6e35add39f760.jpg)
[geek challenge 2019] PHP problem solving record

Introduction to the construction and development of composer private warehouse

CCF access control system (Full Score code + problem solving idea) 201412-1

After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs

Laravel upload error

Repair of incorrect deletion of win10 boot entry

The first dark spring cup dnuictf

Svn password forgetting solution
随机推荐
【BUUCTF】 EasySql
Shangpinhui knowledge points of large e-commerce projects
Sum of squares of two pointers
PS cutting height 1px, Y-axis tiling background image problem
CCF adjacent number pairs (Full Score code + problem solving ideas + skill summary) 201409-1
Solve the problem that codeblocks20.03 on win11 cannot run for the first time
Programming exercises: whole point and circle (solution ideas and code implementation)
[buuctf] [geek challenge 2019] secret file
Effect of shadow around the block after mouse over
V3 03_ Getting started
Summary of FTP network protocol learning
Lihongyi machine learning 2020 homework summary
JS to realize simple lottery function
catkin_ Make reports an error, transfers the location of the workspace, and uses other people's workspace files to cause compilation errors
PHP 2D array change key name
文本匹配——【NAACL 2022】GPL
Learn about data kinship JSON format design from sqlflow JSON format
V3_ Chrome extended Chinese translation document V3 directory
Non decreasing column
@PathVariable