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. JavaFx ObservableList的使用详解

    原文地址:JavaFx ObservableList的使用详解 | Stars-One的杂货小窝 最近在研究MVVM模式,发现可以将之前写的FxRecyclerView控件改造一下,便是开始尝试,尝试 ...

  2. the minimum number of bits required to represent x 最小位数

    src/math/bits/bits.go:296 // --- Len ---// Len returns the minimum number of bits required to repres ...

  3. 关于webservice实现web接口

    package service; import java.util.List; import javax.jws.WebMethod;import javax.jws.WebService; /** ...

  4. H3C交换机DHCP配置

    1.dhcp配置 dhcp enable:开启dhcp功能 dhcp server forbidden-ip 10.1.130.2 10.1.130.10----排除dhcp的一些地址 dhcp se ...

  5. centos 7 部署nginx及libfastcommon

    1.编译环境 (centos)yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib- ...

  6. P3195 [HNOI2008] 玩具装箱(斜率优化DP)

    题目链接 设\(d[i]\)为将前 \(i\) 个玩具装入箱中所需得最小费用 容易得到动态转移方程: \[d[i] = min(d[j] + (s[i]-s[j]+i-j-1-L)^2), (j< ...

  7. Educational Codeforces Round 89 (Rated for Div. 2) C Palindromic Paths

    题目链接:Palindromic Paths 题意: 给你一个n行m列的矩阵,这个矩阵被0或者1所填充,你需要从点(1,1)走到点(n,m).这个时候会有很多路径,每一条路径对应一个01串,你可以改变 ...

  8. NCD 2019 M. NCD Salary

    题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0. 题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道: ...

  9. Codeforces Round #171 (Div. 2) B. Books (模拟队列)

    题意:有一组数,问子数组和最大不超过\(t\)的最多元素个数. 题解:用数组模拟队列,不断的往里面放,队列中的元素之和大于\(t\),就不断地从队头弹出直到满足条件,维护一个最大值即可. 代码: in ...

  10. Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)

    题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...