From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/operators/left_shift/index.html | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/operators/left_shift/index.html (limited to 'files/zh-cn/web/javascript/reference/operators/left_shift') 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 +--- +
{{jsSidebar("Operators")}}
+ +

左移操作符 (<<) 将第一个操作数向左移动指定位数,左边超出的位数将会被清除,右边将会补零。

+ +
{{EmbedInteractiveExample("pages/js/expressions-left-shift.html")}}
+ + + +

语法

+ +
a << b
+
+ +

描述

+ +

左移操作符将第一个操作数向左移动指定位数,左边超出的位数将会被清除,右边将会补零。

+ +

例如, 9 << 2 得出 36:

+ +
.    9 (十进制): 00000000000000000000000000001001 (二进制)
+                  --------------------------------
+9 << 2 (十进制): 00000000000000000000000000100100 (二进制) = 36 (十进制)
+
+ +

移动任意数字 x 至左边 y 位,得出 x * 2 ** y 。
+ 所以例如:9 << 3 等价于 9 * 2³ = 9 * 8 = 72

+ +

例子

+ +

使用左移

+ +
9 << 3; // 72
+
+// 9 * 2³ = 9 * 8 = 72
+
+ +

规范

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

浏览器兼容性

+ + + +

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

+ +

参见

+ + + +

+ +

-- cgit v1.2.3-54-g00ecf