js bitwise operation all in one
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的更多相关文章
- JS魔法堂:再识Bitwise Operation & Bitwise Shift
Brief linkFly的<JavaScript-如果...没有方法>中提及如何手写Math.round方法,各种奇技淫招看着十分过瘾,最让我惊叹的是 ~~(x + )) ,完全通过加法 ...
- algorithm & bitwise operation & the best leetcode solutions
algorithm & bitwise operation & the best leetcode solutions leetcode 136 single-number the b ...
- a bitwise operation 广告投放监控
将随着时间不断增大的数字N个依次编号为1到N的N个球,颜色每次随机为红黑蓝,时间上先后逐个放入篮子中,计算离现在最近的24个球的红.黑.蓝颜色数 广告投放监控 a bitwise operation ...
- HDL之Bitwise operation
1 Verilog 1.1 Bitwise operator Bitwise operators perform a bit wise operation on two operands. They ...
- js logical operation all in one
js logical operation all in one 逻辑运算 Logical AND (&&) Logical AND assignment (&&=) L ...
- js & bitwise operator
js & bitwise operator bitwise operator https://github.com/Advanced-Frontend/Daily-Interview-Ques ...
- C语言之Bit-wise Operation和Logical Operation
首先第一点:十六进制位运算和逻辑运算 都是先转化二进制,后输出结果(十六进制,二或十)Bit-Wise Operations (位运算)包括:& 按位与 | 按位或 ^ 按位异或 ~ 取反 & ...
- 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 ...
- FZU 2105Digits Count(线段树 + 成段更新)
Description Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation 1: AN ...
随机推荐
- 设置一个两边固定中间自适应的css
1.两边浮动,中间自动宽度 给左右两个盒子设置左右浮动,中间的盒子不设置宽度,左右两边边距为左右盒子的宽度,中间盒子的位置必须写在右盒子下面,不然会把右盒子挤下去 如: <div class ...
- http://golang.org/s/better-linker
http://golang.org/s/better-linker The original linker was also simpler than it is now and its implem ...
- 匿名字段 内嵌结构体 interface作为struct field 匿名接口
interface作为struct field,谈谈golang结构体中的匿名接口 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles/19 ...
- 理解 async/await以及对Generator的优势
async await 是用来解决异步的,async函数是Generator函数的语法糖使用关键字async来表示,在函数内部使用 await 来表示异步async函数返回一个 Promise 对象, ...
- springboot2.2.2集成6.5 Elasticsearch
1.0POM文件 <!-- spring-boot --> <dependency> <groupId>org.springframework.boot</g ...
- Linux常用命令详解(第二章)(cat、more、less、head、tail、clear、poweroff、reboot、alias、unalias、uname、hostname、history、whitch、wc、w、who、whoami、)
本章命令(共18个): 1 2 3 4 5 6 7 8 9 10 cat more less head tail clear poweroff reboot alias unalias uname h ...
- 考研机试练习(KY2-KY10)
KY2 成绩排序 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M 本题知识点: 排序 sort struct 题目描述 查找和排序 题目:输入任意(用户,成绩) ...
- charles(2)MAC Charles关闭后无法上网
前言 charles关闭后,发现网页突然打开了,那大概率是设置了代理,但明明已经关闭了charles,这是由于mac网络偏好设置中,使用的是手动代理,将其改为自动即可 解决方法 1 打开网络偏好设置, ...
- 使用eclipse写第一个Java_web的hello_world项目
1.先创建一个Java_web项目 如果你没有下载过Tomcat服务器,不会配置,建议看一下我得这一篇博客:https://www.cnblogs.com/kongbursi-2292702937/p ...
- 在异步或子线程中show窗体的时候要用MethodInvoker委托,要不然show不出来
this.Invoke((MethodInvoker)delegate () { Thread.Sleep(500); this.Hide(); FloatWnd floatWnd = new Flo ...