From 42c588ef3ded2d0cc2f4a71d5d5f90a2c66e534e Mon Sep 17 00:00:00 2001 From: catlair Date: Thu, 10 Mar 2022 18:47:50 +0800 Subject: 与英文版同步并翻译为 zh-CN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operators/left_shift_assignment/index.md | 66 ++++++++-------- .../reference/operators/right_shift/index.md | 87 +++++++++++----------- .../operators/right_shift_assignment/index.md | 66 ++++++++-------- 3 files changed, 100 insertions(+), 119 deletions(-) diff --git a/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.md b/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.md index 4499d3473c..af5ca56da0 100644 --- a/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.md +++ b/files/zh-cn/web/javascript/reference/operators/left_shift_assignment/index.md @@ -1,55 +1,47 @@ --- -title: Left shift assignment (<<=) +title: 左移赋值 (<<=) slug: Web/JavaScript/Reference/Operators/Left_shift_assignment -translation_of: Web/JavaScript/Reference/Operators/Left_shift_assignment +tags: + - Assignment operator + - JavaScript + - Language feature + - Operator + - Reference +browser-compat: javascript.operators.left_shift_assignment --- -
{{jsSidebar("Operators")}}
+{{jsSidebar("Operators")}} -

The left shift assignment operator (<<=) moves the specified amount of bits to the left and assigns the result to the variable.

+左移赋值运算符 (`<<=`) 将变量向左移动指定数量的位,并将结果赋值给变量。 -
{{EmbedInteractiveExample("pages/js/expressions-left-shift-assignment.html")}}
+{{EmbedInteractiveExample("pages/js/expressions-left-shift-assignment.html")}} +## 语法 +```js +x <<= y // x = x << y +``` +## 例子 +### 使用左移赋值 -

语法

- -
Operator: x <<= y
-Meaning:  x   = x << y
- -

Examples

- -

Using left shift assignment

- -
let a = 5;
+```js
+let a = 5;
 // 00000000000000000000000000000101
 
-a <<= 2; // 20
-// 00000000000000000000000000010100
- -

Specifications

- - - - - - - - - - -
Specification
{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}
+a <<= 2; // 20 +// 00000000000000000000000000010100 +``` -

Browser compatibility

+## 规范 +{{Specifications}} +## 浏览器兼容性 -

{{Compat("javascript.operators.left_shift_assignment")}}

+{{Compat("javascript.operators.left_shift_assignment")}} -

See also

+## 参考 - +- [JS 指南中的赋值运算符](/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators#assignment) +- [左移运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Left_shift) 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 --- -
{{jsSidebar("Operators")}}
+{{jsSidebar("Operators")}} -

The right shift 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".

+**右移操作符 (`>>`)** 是将一个操作数按指定移动的位数向右移动,右边移出位被丢弃,左边移出的空位补符号位(最左边那位)。 -
{{EmbedInteractiveExample("pages/js/expressions-right-shift.html")}}
+{{EmbedInteractiveExample("pages/js/expressions-right-shift.html")}} -

语法

+## 语法 -
a >> b
-
+```js +a >> b +``` -

Description

+## 描述 -

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".

+**右移操作符 (`>>`)** 是将一个操作数按指定移动的位数向右移动。 +右边移出位将被丢弃,然后用最左边的这一位(符号位)填充左边的空位。 +由于新的数字最左边位与之前数字的最左边位是相同值,故符号位(最左边的位)不会改变,因此被称为“符号位传播” (sign-propagating). -

For example, 9 >> 2 yields 2:

+例如 `9 >> 2` 得到 2: -
.    9 (base 10): 00000000000000000000000000001001 (base 2)
+```js
+.    9 (十进制): 00000000000000000000000000001001 (二进制)
                   --------------------------------
-9 >> 2 (base 10): 00000000000000000000000000000010 (base 2) = 2 (base 10)
-
+9 >> 2 (十进制): 00000000000000000000000000000010 (二进制) = 2 (十进制) +``` -

Likewise, -9 >> 2 yields -3, because the sign is preserved:

+同理, `-9 >> 2` 得到 `-3`, 因为它的符号位得到保留: -
.    -9 (base 10): 11111111111111111111111111110111 (base 2)
+```js
+.    -9 (base 10): 11111111111111111111111111110111 (base 2)
                    --------------------------------
--9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10)
-
+-9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10) +``` -

Examples

+## 例子 -

Using right shift

+### 使用右移操作 -
 9 >> 2; //  2
--9 >> 2; // -3
-
+```js + 9 >> 2; // 2 +-9 >> 2; // -3 +``` -

Specifications

+## 规范 - - - - - - - - - - - -
Specification
{{SpecName('ESDraft', '#sec-bitwise-shift-operators', 'Bitwise Shift Operators')}}
+{{Specifications}} -

Browser compatibility

+## 浏览器兼容性 +{{Compat}} +## 参见 -

{{Compat("javascript.operators.right_shift")}}

- -

See also

- - +- [JS 指南中的位运算](/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) +- [右移赋值操作符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Right_shift_assignment) diff --git a/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.md b/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.md index f3698e9737..7afdf1311e 100644 --- a/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.md +++ b/files/zh-cn/web/javascript/reference/operators/right_shift_assignment/index.md @@ -1,55 +1,47 @@ --- -title: Right shift assignment (>>=) +title: 右移赋值 (>>=) slug: Web/JavaScript/Reference/Operators/Right_shift_assignment -translation_of: Web/JavaScript/Reference/Operators/Right_shift_assignment +tags: + - Assignment operator + - JavaScript + - Language feature + - Operator + - Reference +browser-compat: javascript.operators.right_shift_assignment --- -
{{jsSidebar("Operators")}}
+{{jsSidebar("Operators")}} -

The right shift assignment operator (>>=) moves the specified amount of bits to the right and assigns the result to the variable.

+右移赋值运算符 (`>>=`) 将变量向右移动指定数量的位,并将结果赋值给变量。 -
{{EmbedInteractiveExample("pages/js/expressions-right-shift-assignment.html")}}
+{{EmbedInteractiveExample("pages/js/expressions-right-shift-assignment.html")}} +## 语法 +```js +x >>= y // x = x >> y +``` +## 例子 +### 使用右移赋值运算符 -

语法

- -
Operator: x >>= y
-Meaning:  x   = x >> y
- -

Examples

- -

Using right shift assignment

- -
let a = 5; //   (00000000000000000000000000000101)
-a >>= 2;   // 1 (00000000000000000000000000000001)
+```js
+let a = 5; //   (00000000000000000000000000000101)
+a >>= 2;   // 1 (00000000000000000000000000000001)
 
 let b = -5; //  (-00000000000000000000000000000101)
-b >>= 2;  // -2 (-00000000000000000000000000000010)
- -

Specifications

- - - - - - - - - - -
Specification
{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}
+b >>= 2; // -2 (-00000000000000000000000000000010) +``` -

Browser compatibility

+## 规范 +{{Specifications}} +## 浏览器兼容性 -

{{Compat("javascript.operators.right_shift_assignment")}}

+{{Compat}} -

See also

+## 参考 - +- [JS 指南中的赋值运算符](/zh-CN/docs/Web/JavaScript/Guide/Expressions_and_Operators#assignment) +- [右移运算符](/zh-CN/docs/Web/JavaScript/Reference/Operators/Right_shift) -- cgit v1.2.3-54-g00ecf