当前位置: 首页 > 文档资料 > ES6 入门教程 >

Show 例子 4

优质
小牛编辑
121浏览
2023-12-01

JavaScript支持以下按位运算符。

例子 (Example)

var a = 2; // Bit presentation 10 
var b = 3; // Bit presentation 11 
var result; 
result = (a & b); 
console.log("(a & b) => ", result); 
result = (a | b); 
console.log("(a | b) => ", result); 
result = (a ^ b); 
console.log("(a ^ b) => ", result); 
result = (~b); 
console.log("(~b) => ", result); 
result = (a << b); 
console.log("(a << b) => ", result); 
result = (a >> b); 
console.log("(a >> b) => ", result); 

成功执行上述程序后,将显示以下输出。

(a & b) =>  2 
(a | b) =>  3 
(a ^ b) =>  1 
(~b) =>  -4 
(a << b) =>  16 
(a >> b) =>  0