diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/operators/left_shift/index.html | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-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/left_shift/index.html')
| -rw-r--r-- | files/zh-cn/web/javascript/reference/operators/left_shift/index.html | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/left_shift/index.html b/files/zh-cn/web/javascript/reference/operators/left_shift/index.html new file mode 100644 index 0000000000..aba9c6bee2 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/operators/left_shift/index.html @@ -0,0 +1,72 @@ +--- +title: 左移 (<<) +slug: Web/JavaScript/Reference/Operators/Left_shift +translation_of: Web/JavaScript/Reference/Operators/Left_shift +--- +<div>{{jsSidebar("Operators")}}</div> + +<p><strong>左移操作符 (<code><<</code>)</strong> 将第一个操作数向左移动指定位数,左边超出的位数将会被清除,右边将会补零。</p> + +<div>{{EmbedInteractiveExample("pages/js/expressions-left-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> << <var>b</var></code> +</pre> + +<h2 id="描述">描述</h2> + +<p>左移操作符将第一个操作数向左移动指定位数,左边超出的位数将会被清除,右边将会补零。</p> + +<p>例如, <code>9 << 2</code> 得出 36:</p> + +<pre class="brush: js notranslate">. 9 (十进制): 00000000000000000000000000001001 (二进制) + -------------------------------- +9 << 2 (十进制): 00000000000000000000000000100100 (二进制) = 36 (十进制) +</pre> + +<p>移动任意数字 <code>x</code> 至左边 <code>y</code> 位,得出 <code>x * 2 ** y</code> 。<br> + 所以例如:<code>9 << 3</code> 等价于 <code>9 * 2³ = 9 * 8 = 72</code>。</p> + +<h2 id="例子">例子</h2> + +<h3 id="使用左移">使用左移</h3> + +<pre class="brush: js notranslate">9 << 3; // 72 + +// 9 * 2³ = 9 * 8 = 72 +</pre> + +<h2 id="规范">规范</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="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("javascript.operators.left_shift")}}</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/Left_shift_assignment">Left shift assignment operator</a></li> +</ul> + +<p> + <audio style="display: none;"></audio> +</p> |
