Home >Web Front-end >JS Tutorial >Introduction to the use of Javascript bitwise left shift operator (<<)_Basic knowledge

Introduction to the use of Javascript bitwise left shift operator (<<)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:01:332324browse

The bitwise left shift operator (<<)
Shifts the bits of an expression to the left.

result = expression1 << expression2

Parameter
result

Any variable.

expression1

Any expression.

expression2

Any expression.

Explanation
<< operator shifts all bits of expression1 to the left by the number of digits specified by expression2. For example:

var temp
temp = 14 << 2
The value of variable temp is 56, because 14 (that is, 00001110 in binary) shifted two places to the left equals 56 (that is, 00111000 in binary).

Javascript bitwise left shift operator (<<) converts the expression number into binary and then shifts the bits of the expression to the left.

result = [number to be shifted] << [number of shifts]

The bitwise left shift operator (<<) shifts the bits of [the number to be shifted] to the left by the number of digits specified in [number of bits to shift]. For example:

Copy code The code is as follows:

var temp;
temp = 14 << ; 2;
/*
14 in binary is 00111000
00001110. Shift 2 bits to the left 00111000 = 56
*/
alert(temp);
// Pop up【56】
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn