aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/bitwise_or
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/operators/bitwise_or
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/operators/bitwise_or')
-rw-r--r--files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html108
1 files changed, 108 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html b/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html
new file mode 100644
index 0000000000..dcd9c54de0
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/operators/bitwise_or/index.html
@@ -0,0 +1,108 @@
+---
+title: Bitwise OR (|)
+slug: Web/JavaScript/Reference/Operators/Bitwise_OR
+translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR
+---
+<div>{{jsSidebar("Operators")}}</div>
+
+<p>The bitwise OR operator (<code>|</code>) returns a <code>1</code> in each bit position for which the corresponding bits of either or both operands are <code>1</code>s.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/expressions-bitwise-or.html")}}</div>
+
+<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate"><code><var>a</var> | <var>b</var></code>
+</pre>
+
+<h2 id="描述">描述</h2>
+
+<p>The operands are converted to 32-bit integers and expressed by a series of bits (zeroes and ones). Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32 bit integer:</p>
+
+<pre class="brush: js notranslate">Before: 11100110111110100000000000000110000000000001
+After: 10100000000000000110000000000001</pre>
+
+<p>Each bit in the first operand is paired with the corresponding bit in the second operand: <em>first bit</em> to <em>first bit</em>, <em>second bit</em> to <em>second bit</em>, and so on.</p>
+
+<p>The operator is applied to each pair of bits, and the result is constructed bitwise.</p>
+
+<p>The truth table for the OR operation is:</p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th class="header" scope="col">a</th>
+ <th class="header" scope="col">b</th>
+ <th class="header" scope="col">a OR b</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>0</td>
+ <td>0</td>
+ <td>0</td>
+ </tr>
+ <tr>
+ <td>0</td>
+ <td>1</td>
+ <td>1</td>
+ </tr>
+ <tr>
+ <td>1</td>
+ <td>0</td>
+ <td>1</td>
+ </tr>
+ <tr>
+ <td>1</td>
+ <td>1</td>
+ <td>1</td>
+ </tr>
+ </tbody>
+</table>
+
+<pre class="brush: js notranslate">. 9 (base 10) = 00000000000000000000000000001001 (base 2)
+ 14 (base 10) = 00000000000000000000000000001110 (base 2)
+ --------------------------------
+14 | 9 (base 10) = 00000000000000000000000000001111 (base 2) = 15 (base 10)
+</pre>
+
+<p>Bitwise ORing any number <code><var>x</var></code> with <code>0</code> yields <code><var>x</var></code>.</p>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="Using_bitwise_OR">Using bitwise OR</h3>
+
+<pre class="brush: js notranslate">// 9 (00000000000000000000000000001001)
+// 14 (00000000000000000000000000001110)
+
+14 | 9;
+// 15 (00000000000000000000000000001111)</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#prod-BitwiseORExpression', 'Bitwise OR expression')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("javascript.operators.bitwise_or")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise">Bitwise operators in the JS guide</a></li>
+ <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR_assignment">Bitwise OR assignment operator</a></li>
+</ul>