我试图理解JavaScript中二进制运算符(只有二元运算符)的可能性.到目前为止,我发现的二元运算符列表如下.它们主要来自此列表,但是有什么遗漏?
注意,我特意只使用二元运算符,根据上面列出的源,它被定义为与两个对象一起使用的二元运算符(这是否准确?).我还添加了@samsamX的附加内容.
+ //Add
- //Subtract
/ //Divided by
* //Multiple
% //Modulus
< //Less than
> //Greater than
& //AND
| //OR
^ //XOR
~ //Invert each bits
<< //Move all bits onto the left
>> //Move all bits onto the right
>>> //Move all bits onto the right and fill left end with 0
Run Code Online (Sandbox Code Playgroud) 我有一段我想了解的Javascript代码
// read big-endian (network byte order) 32-bit float
readFloat32 = function(data, offset) {
var b1 = data.charCodeAt(offset) & 0xFF,
b2 = data.charCodeAt(offset+1) & 0xFF,
b3 = data.charCodeAt(offset+2) & 0xFF,
b4 = data.charCodeAt(offset+3) & 0xFF;
var sign = 1 - (2*(b1 >> 7)); //<--- here it is and 2 lines below
var exp = (((b1 << 1) & 0xff) | (b2 >> 7)) - 127;
var sig = ((b2 & 0x7f) << 16) | (b3 << 8) | b4;
if …Run Code Online (Sandbox Code Playgroud)