当前位置:网站首页>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 .
边栏推荐
- 如何使用lxml判断网站公告是否更新
- How to delete an attribute or method of an object
- SQL Injection (AJAX/JSON/jQuery)
- Go 1.16.4: purpose of go mod tidy
- Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
- [acnoi2022] guess numbers
- Summary of common error reporting problems and positioning methods of thrift
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- Go language web development series 27: Gin framework: using gin swagger to implement interface documents
- PhpMyAdmin stage file contains analysis traceability
猜你喜欢

GoLand 2021.1.1: configure the multi line display of the tab of the open file

Qt学习20 Qt 中的标准对话框(中)

Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm

jvm-类加载

MySQL data processing value addition, deletion and modification

MySQL 数据处理值增删改

核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)

Go language web development series 30: gin: grouping by version for routing

Redis: redis data structure and key operation commands
[email protected] (FE) | glycyrrhetinic acid modified metal organ"/>Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
随机推荐
FPGA test method takes mentor tool as an example
Use and design of Muduo buffer class
FPGA测试方法以Mentor工具为例
There is nothing new under the sun. Can the meta universe go higher?
金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
GoLand 2021.1: rename the go project
Ocean CMS vulnerability - search php
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
QT learning 20 standard dialog box in QT (middle)
QT learning 24 layout manager (III)
MySQL 数据增删改查综合案例
Uniapp tips - scrolling components
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
可编程逻辑器件软件测试
Redis: redis data structure and key operation commands
叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
JS download files through URL links
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
