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
Release: 2016-05-16 17:01:33
Original
2323 people have browsed it

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】
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template