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 | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 files/ja/web/javascript/reference/operators/left_shift/index.html (limited to 'files/ja/web/javascript/reference/operators/left_shift/index.html') diff --git a/files/ja/web/javascript/reference/operators/left_shift/index.html b/files/ja/web/javascript/reference/operators/left_shift/index.html new file mode 100644 index 0000000000..9a274f84b2 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/left_shift/index.html @@ -0,0 +1,77 @@ +--- +title: 左シフト (<<) +slug: Web/JavaScript/Reference/Operators/Left_shift +tags: + - Bitwise operator + - JavaScript + - Language feature + - Operator + - Reference + - ビット演算子 + - 演算子 + - 言語機能 +translation_of: Web/JavaScript/Reference/Operators/Left_shift +--- +
{{jsSidebar("Operators")}}
+ +

左シフト演算子 (<<)は、1つ目のオペランドを指定されたビット数だけ左にずらします。左にずらしてあふれたビットは廃棄されます。0のビットが右からずれて入ります。

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

構文

+ +
a << b
+
+ +

解説

+ +

この演算子は、1つ目のオペランドを指定されたビット数だけ左にずらします。左にずらしてあふれたビットは廃棄されます。0のビットが右からずれて入ります。

+ +

例えば 9 << 2 は 36 になります。

+ +
.    9 (10進数): 00000000000000000000000000001001 (2進数)
+                  --------------------------------
+9 << 2 (10進数): 00000000000000000000000000100100 (2進数) = 36 (10進数)
+
+ +

任意の数 xy ビット分だけ左にビット単位にずらすと、 x * 2 ** y になります。
+ ですから、例えば 9 << 39 * (2 ** 3) = 9 * (8) = 72 になります。

+ +

+ +

左シフトの使用

+ +
9 << 3; // 72
+
+// 9 * (2 ** 3) = 9 * (8) = 72
+
+ +

仕様書

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

ブラウザーの互換性

+ + + +

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

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf