aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/right_shift
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/right_shift
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/right_shift')
-rw-r--r--files/zh-cn/web/javascript/reference/operators/right_shift/index.html75
1 files changed, 75 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift/index.html b/files/zh-cn/web/javascript/reference/operators/right_shift/index.html
new file mode 100644
index 0000000000..267a2c0ccc
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/operators/right_shift/index.html
@@ -0,0 +1,75 @@
+---
+title: Right shift (>>)
+slug: Web/JavaScript/Reference/Operators/Right_shift
+translation_of: Web/JavaScript/Reference/Operators/Right_shift
+---
+<div>{{jsSidebar("Operators")}}</div>
+
+<p>The <strong>right shift operator (<code>&gt;&gt;</code>)</strong> shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Copies of the leftmost bit are shifted in from the left. Since the new leftmost bit has the same value as the previous leftmost bit, the sign bit (the leftmost bit) does not change. Hence the name "sign-propagating".</p>
+
+<div>{{EmbedInteractiveExample("pages/js/expressions-right-shift.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> &gt;&gt; <var>b</var></code>
+</pre>
+
+<h2 id="Description">Description</h2>
+
+<p>This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Copies of the leftmost bit are shifted in from the left. Since the new leftmost bit has the same value as the previous leftmost bit, the sign bit (the leftmost bit) does not change. Hence the name "sign-propagating".</p>
+
+<p>For example, <code>9 &gt;&gt; 2</code> yields 2:</p>
+
+<pre class="brush: js notranslate">. 9 (base 10): 00000000000000000000000000001001 (base 2)
+ --------------------------------
+9 &gt;&gt; 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10)
+</pre>
+
+<p>Likewise, <code>-9 &gt;&gt; 2</code> yields <code>-3</code>, because the sign is preserved:</p>
+
+<pre class="brush: js notranslate">. -9 (base 10): 11111111111111111111111111110111 (base 2)
+ --------------------------------
+-9 &gt;&gt; 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10)
+</pre>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="Using_right_shift">Using right shift</h3>
+
+<pre class="brush: js notranslate"> 9 &gt;&gt; 2; // 2
+-9 &gt;&gt; 2; // -3
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-bitwise-shift-operators', 'Bitwise Shift Operators')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("javascript.operators.right_shift")}}</p>
+
+<h2 id="See_also">See also</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/Right_shift_assignment">Right shift assignment operator</a></li>
+</ul>
+
+<p>
+ <audio style="display: none;"></audio>
+</p>