JavaScript Bitwise Left Shift Assignment Operators

Perform Bitwise Left Shift Assignment Operations In JavaScript

A bitwise operation takes values and operates at the most basic unit of information whose logical state is represented by 1 or 0.

JavaScript bitwise operators convert numbers to 32-bit integers otherwise it will use BigInt if applicable. Therefore bitwise left shift (<<) binary operation compares each bit of 2 operands and shift the bits of a number to the left and fill 0 on voids left as a result. The format is (number) << (number of shifts) such a 2 << 1 to shift the bits of 2 to the left by 1 so that 0010 for 2 becomes binary 0100 or decimal 4. The left shift operator multiples the number by any power of 2.

An operand is the object of a mathematical operation. Operands for the bitwise left shift are integers in the form of numbers or BigInt and the logical shift leftmost bit depends on the sign of the initial number.

Bitwise Left Shift Assignment Operators For JavaScript

Glossary:

Binary Operation

Mathematical rule for combining two operands to produce another.

Logical Shift

Discards the least significant bits and filling with zeros.

BigInt

Used to represent numeric values too large for number data type.

Truth Table

Illustrate the behavior of bitwise logical operators.

Bitwise Left Shift Assignment Operators

Ojamboshop.com Learning JavaScript Bitwise Left Shift Assignment Operators
Name Description Example
<<= Bitwise Left Shift assignment result to one operand num1 <<= 5;
<< Bitwise Left Shift num1 << num2;
Truth Table
num1 num2 result
0 0 0
0 1 0
1 0 1
1 1 2
Name Description Example

JavaScript Bitwise Left Shift Assignment Operators Snippet

// OjamboShop.com Learning JavaScript Bitwise Left Shift Assignment Operators Tutorial
let num1 = 5; // Binary 101
let num2 = 3; // Binary 11
let num3 = 1234567890123456789012345678901234567890n; // Binary 1110100000110010010010000001110101110000001101101111110011101110001010110010111100010111111001011011001110001111110000101011010010
let num4 = 12n; // Binary 1100
console.log(num1 << num2);
console.log(num2 << num1);
console.log(3 << num1);
console.log(5 << num2);
// BitInt 
console.log(num3 << num4);
console.log(5n << 3n);
// Bitwise Left Shift Assignment
let num5 = 10; // Binary 1010
num5 <<= 6; // Binary 1010000000
console.log(num5);

JavaScript Bitwise Left Shift Assignment Operators Code
OjamboShop.com Web IDE JavaScript Bitwise Left Shift Assignment Operators Code

JavaScript Comparison Operators Result
OjamboShop.com Web IDE Displaying JavaScript Bitwise Left Shift Assignment Operators Result


Usage

You can use any IDE or text editor and the web browser to compile and execute JavaScript code. For this tutorial, the OjamboShop.com Learning JavaScript Course Web IDE can used to input and compile JavaScript code for the bitwise left shift assignment operators.

Open Source

JavaScript follows the ECMAScript standard and is licensed under the W3C Software License by web browser vendors and runtime environment vendors. This allows commercial use, modification, distribution, and allows making derivatives proprietary.

Learn Programming Courses:

Courses are optimized for your web browser on any device.

OjamboShop.com Learning JavaScript Course
OjamboShop.com Learning JavaScript Interactive Online Course

Limited Time Offer:

OjamboShop.com is offering 20% off coupon code SCHOOL for Learning JavaScript Course until End Day 2024.

Learn Programming Ebooks:

Ebooks can be downloaded to your reader of choice.

OjamboShop.com Learning JavaScript Ebook
OjamboShop.com Learning JavaScript Ebook Cover Page

Conclusion:

JavaScript makes it easy to use the bitwise left shift assignment operators. Use bitwise left shift assignment operators to perform left shift on the two operands and assign the result to the left operand. Therefore the left shift operator multiples the number by any power of 2.

Take this opportunity to learn the JavaScript programming language by making a one-time purchase at Learning JavaScript Course. A web browser is the only thing needed to learn JavaScript in 2024 at your leisure. All the developer tools are provided right in your web browser.

If you prefer to download ebook versions for your reader then you may purchase at Learning JavaScript Ebook

References:

Leave a Reply

Your email address will not be published. Required fields are marked *