diff options
author | catlair <catlair@qq.com> | 2022-03-10 18:47:50 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-03-15 21:36:59 +0800 |
commit | 42c588ef3ded2d0cc2f4a71d5d5f90a2c66e534e (patch) | |
tree | 77011a149d6dab2c49864c170528b6a92bff96d5 /files/zh-cn/web/javascript/reference/operators/right_shift | |
parent | 283c65cafc545c37b57ed0493b5c5e053ecbbb92 (diff) | |
download | translated-content-42c588ef3ded2d0cc2f4a71d5d5f90a2c66e534e.tar.gz translated-content-42c588ef3ded2d0cc2f4a71d5d5f90a2c66e534e.tar.bz2 translated-content-42c588ef3ded2d0cc2f4a71d5d5f90a2c66e534e.zip |
与英文版同步并翻译为 zh-CN
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.md | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift/index.md b/files/zh-cn/web/javascript/reference/operators/right_shift/index.md index b8275e16d7..4c9d5d2898 100644 --- a/files/zh-cn/web/javascript/reference/operators/right_shift/index.md +++ b/files/zh-cn/web/javascript/reference/operators/right_shift/index.md @@ -1,69 +1,66 @@ --- -title: Right shift (>>) +title: 右移 (>>) slug: Web/JavaScript/Reference/Operators/Right_shift -translation_of: Web/JavaScript/Reference/Operators/Right_shift +tags: + - Bitwise operator + - JavaScript + - Language feature + - Operator + - Reference +browser-compat: javascript.operators.right_shift --- -<div>{{jsSidebar("Operators")}}</div> +{{jsSidebar("Operators")}} -<p>The <strong>right shift operator (<code>>></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> +{{EmbedInteractiveExample("pages/js/expressions-right-shift.html")}} -<h2 id="语法">语法</h2> +## 语法 -<pre class="syntaxbox"><code><var>a</var> >> <var>b</var></code> -</pre> +```js +a >> b +``` -<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> +**右移操作符 (`>>`)** 是将一个操作数按指定移动的位数向右移动。 +右边移出位将被丢弃,然后用最左边的这一位(符号位)填充左边的空位。 +由于新的数字最左边位与之前数字的最左边位是相同值,故符号位(最左边的位)不会改变,因此被称为“符号位传播” (sign-propagating). -<p>For example, <code>9 >> 2</code> yields 2:</p> +例如 `9 >> 2` 得到 2: -<pre class="brush: js">. 9 (base 10): 00000000000000000000000000001001 (base 2) +```js +. 9 (十进制): 00000000000000000000000000001001 (二进制) -------------------------------- -9 >> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10) -</pre> +9 >> 2 (十进制): 00000000000000000000000000000010 (二进制) = 2 (十进制) +``` -<p>Likewise, <code>-9 >> 2</code> yields <code>-3</code>, because the sign is preserved:</p> +同理, `-9 >> 2` 得到 `-3`, 因为它的符号位得到保留: -<pre class="brush: js">. -9 (base 10): 11111111111111111111111111110111 (base 2) +```js +. -9 (base 10): 11111111111111111111111111110111 (base 2) -------------------------------- --9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10) -</pre> +-9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10) +``` -<h2 id="Examples">Examples</h2> +## 例子 -<h3 id="Using_right_shift">Using right shift</h3> +### 使用右移操作 -<pre class="brush: js"> 9 >> 2; // 2 --9 >> 2; // -3 -</pre> +```js + 9 >> 2; // 2 +-9 >> 2; // -3 +``` -<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> +{{Specifications}} -<h2 id="Browser_compatibility">Browser compatibility</h2> +## 浏览器兼容性 +{{Compat}} +## 参见 -<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> +- [JS 指南中的位运算](/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) +- [右移赋值操作符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Right_shift_assignment) |