>>,<<,|的含义和&在JavaScript中 [英] Meaning of >>, <<, | and & in JavaScript

查看:142
本文介绍了>>,<<,|的含义和&在JavaScript中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用base64编码脚本,但它在JSLint中抛出了很多警告。

I was working with a base64 encoding script, but it is throwing a lot of warnings in JSLint.

有人可以告诉我这些符号在JavaScript中的含义是什么?

Can someone tell me what's the meaning of these symbols in JavaScript?

>> << | &

以下是一个示例带有这些符号的代码:

Here's an example of code with those symbols:

if ((c > 127) && (c < 2048)) {
    utftext += String.fromCharCode((c >> 6) | 192);
    utftext += String.fromCharCode((c & 63) | 128);
}

我想重写一下,以便JSLint验证它。

I would like to rewrite this so that it gets validated by JSLint.

推荐答案

这些符号指的是某些按位操作

>> Right shift
<< Left shift
|  Bitwise OR
&  Bitwise AND

在链接的维基百科页面上阅读有关他们所做工作的更多信息。

Read up on the linked Wikipedia page for more information on what they do.

请参阅此处了解JSLint对这些内容发出警告的原因操作。它主要与效率有关(即,JavaScript在内部使用浮点数,并且使用按位运算符转换为整数和返回效率低)。

See here for why JSLint warns on these operations. It largely has to do with efficiency (i.e., JavaScript uses floating point numbers internally and it's inefficient to cast to integers and back with bitwise operators).

右移和左移可以用除以2和2乘以替换。

Right shift and left shift can be replaced with dividing by and multiplying by 2, respectively.

这篇关于&gt;&gt;,&lt;&lt;,|的含义和&amp;在JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆