js bitwise operation all in one

位运算

&

按位与


|

按位或


^

按位异或 / XOR

let a = 5;      // 00000000000000000000000000000101
a ^= 3; // 00000000000000000000000000000011
console.log(a); // 00000000000000000000000000000110 let b = 5; // 00000000000000000000000000000101
b = b ^ 3; // 00000000000000000000000000000011
console.log(b); // 00000000000000000000000000000110
// 6

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR_assignment

~

按位取反/按位非


>>

按位右移


<<

按位左移

const a = 5;         // 00000000000000000000000000000101
const b = 2; // 00000000000000000000000000000010
console.log(a << b); // 00000000000000000000000000010100
// 20 const x = 5; // 00000000000000000000000000000101
const y = 3; // 00000000000000000000000000000011
console.log(x << y); // 00000000000000000000000000101000
// 40
(5 << 3).toString(2)
// "101000"
parseInt("101000", 2)
// 40

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift

refs

位运算(&、|、^、~、>>、<<)

https://www.runoob.com/w3cnote/bit-operation.html

js 进制转换

https://www.cnblogs.com/xgqfrms/p/13532592.html

^

https://www.cnblogs.com/xgqfrms/p/13526984.html



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


js bitwise operation all in one的更多相关文章

  1. JS魔法堂:再识Bitwise Operation & Bitwise Shift

    Brief linkFly的<JavaScript-如果...没有方法>中提及如何手写Math.round方法,各种奇技淫招看着十分过瘾,最让我惊叹的是 ~~(x + )) ,完全通过加法 ...

  2. algorithm & bitwise operation & the best leetcode solutions

    algorithm & bitwise operation & the best leetcode solutions leetcode 136 single-number the b ...

  3. a bitwise operation 广告投放监控

    将随着时间不断增大的数字N个依次编号为1到N的N个球,颜色每次随机为红黑蓝,时间上先后逐个放入篮子中,计算离现在最近的24个球的红.黑.蓝颜色数 广告投放监控 a bitwise operation ...

  4. HDL之Bitwise operation

    1 Verilog 1.1 Bitwise operator Bitwise operators perform a bit wise operation on two operands. They ...

  5. js logical operation all in one

    js logical operation all in one 逻辑运算 Logical AND (&&) Logical AND assignment (&&=) L ...

  6. js & bitwise operator

    js & bitwise operator bitwise operator https://github.com/Advanced-Frontend/Daily-Interview-Ques ...

  7. C语言之Bit-wise Operation和Logical Operation

    首先第一点:十六进制位运算和逻辑运算 都是先转化二进制,后输出结果(十六进制,二或十)Bit-Wise Operations (位运算)包括:& 按位与 | 按位或 ^ 按位异或 ~ 取反 & ...

  8. CF778B(round 402 div.2 E) Bitwise Formula

    题意: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied t ...

  9. FZU 2105Digits Count(线段树 + 成段更新)

    Description Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation 1: AN ...

随机推荐

  1. jQuery 文本段落展开和折叠效果

    jQuery 文本段落展开和折叠效果 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" c ...

  2. The Garbage Collection Handbook

    The Garbage Collection Handbook The Garbage Collection Handbook http://gchandbook.org/editions.html ...

  3. https://twistedmatrix.com/documents/current/core/howto/defer.html

    https://twistedmatrix.com/documents/current/core/howto/defer.html

  4. Vim配置及其他注意事项

    常用的一些配置 set t_ti= set t_te= "这两个比较特殊,后边说 set termencoding=utf-8 set encoding=utf-8 set fileenco ...

  5. java 将内容写入文件 txt

    @Test //将内容写入文件 public void xieru() throws Exception{ FileWriter fileWriter=new FileWriter("d:\ ...

  6. (4)Linux常用的运维平台和工具

    运维工程师使用的运维平台和工具包括: Web服务器:apache.tomcat.nginx.lighttpd 监控:nagios.ganglia.cacti.zabbix 自动部署:ansible.s ...

  7. PHP-数组相关知识总结

    PHP-数组相关知识总结 (一)数组创建 //创建数组(php5.4 起可以使用短数组定义语法,用 [] 替代 array()) <?php$array = array(    "fo ...

  8. dedecms不能保存jpeg格式图片的解决方法

    方法如下: 进入织梦的后台管理目录,默认是dede文件夹,找到/inc/inc_archives_functions.php文件. 在文件里查找gif|jpg|,我找到了4个, 在它们后面加jpeg的 ...

  9. 四. SpringCloud负载均衡与调用

    1. Ribbon概述 1.1 Ribbon是什么 SpringCloud Ribbon是基于Netflix Ribbon实现的一套客户端,是负载均衡的工具. Ribbon是Netflix发布的开源项 ...

  10. 微信支付V3 SDK Payment Spring Boot 1.0.6 发布,实现留守红包,助力抗疫

    春节将至,为防控疫情,多地政府提倡员工.外来务工者留守本地过年,并鼓励企业向员工发放"留守红包".为此,微信支付推出"春节留守红包"能力,希望可以协助有发放需求 ...