当前位置:网站首页>JS shift operators (< <,> > and > > >)
JS shift operators (< <,> > and > > >)
2022-07-03 14:06:00 【Cupid510】
JS Shift Operators (<<、>> and >>>)
Shift operation is to perform regular low shift on binary . Shift operation can design many wonderful effects , It is widely used in graphics and image programming .
“<<” Operator
“<<” Operator performs a left shift operation . During the shift operation , The sign bit remains unchanged . If the right side is empty , Is automatically filled with 0; beyond 32 The value of a , Automatically discard .
for example : Put the numbers 5 Move to the left 2 position , The return value is 20.
console.log(5 << 2); // Return value 20
Demonstrate with a formula , As shown in the figure .
“>>” Operator
“>>” Operator performs a signed right shift operation . Opposite to the left shift operation , It is the 32 All significant bits in the bit number are shifted to the right as a whole , Then fill the empty bit with the value of the sign bit . Values exceeded during the move will be discarded .
For example, put the value 1000 Move right 8 position , The return value is 3.
console.log(1000 >> 8); // Return value 3
Demonstrate with a formula , As shown in the figure .
Put the number -1000 Move right 8 position , The return value is -4.
console.log(-1000 >> 8); // Return value -4
Demonstrate with a formula , As shown in the figure . When the sign bit value is 1 when , Then all the empty bits on the left side of the significant bit are used 1 Fill in .
“>>>” Operator
“>>>” Operator performs an unsigned shift right operation . It takes the unsigned 32 Bit integers all bits are shifted to the right as a whole . For the shift right operation of an unsigned number or a positive number , The result of the shift right operation is the same as that of the shift right operation .
The return value of the following two lines of expression is the same .
console.log(1000 >> 8); // Return value 3
console.log(1000 >> 8); // Return value 3
For negative numbers , Move right without sign will use 0 To fill all the vacancies , At the same time, negative numbers are treated as positive numbers , The results will be very large, so , Be very careful when using the unsigned shift right operator , Avoid unexpected mistakes .
console.log(-1000 >> 8); // Return value -4
console.log(-1000 >>> 8); // Return value
16777212
Demonstrate with a formula , As shown in the figure . The left vacancy is no longer filled with the value of the sign bit , It's about using 0 Fill in .
边栏推荐
- Current situation, analysis and prediction of information and innovation industry
- Dynamic programming 01 knapsack and complete knapsack
- jvm-对象生命周期
- [bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
- QT learning 22 layout manager (I)
- How to use lxml to judge whether the website announcement is updated
- Go language web development series 30: gin: grouping by version for routing
- SQL Injection (AJAX/JSON/jQuery)
- MySQL data processing value addition, deletion and modification
- Halcon combined with C # to detect surface defects -- Halcon routine autobahn
猜你喜欢
Qt学习18 登录对话框实例分析
Article content typesetting and code highlighting
Screenshot of the operation steps of upload labs level 4-level 9
RocksDB LRUCache
Go language unit test 3: go language uses gocovey library to do unit test
The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
QT learning 17 dialog box and its types
SQL Injection (POST/Select)
Page generation QR code
随机推荐
GoLand 2021.1: rename the go project
Field problems in MySQL
Conversion function and explicit
FPGA测试方法以Mentor工具为例
Uniapp skills - scrolling components -1
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
Go 1.16.4: manage third-party libraries with Mod
QT learning 24 layout manager (III)
Redis: operation command of string type data
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
Implementation of Muduo accept connection, disconnection and sending data
Windos creates Cordova prompt because running scripts is prohibited on this system
How to promote the progress of project collaboration | community essay solicitation
如何使用lxml判断网站公告是否更新
Golang — template
Qt学习24 布局管理器(三)
Golang - command line tool Cobra
[Jilin University] information sharing of postgraduate entrance examination and re examination
1px problem of mobile terminal
jvm-运行时数据区