Open In App

Zero Fill Right Shift (>>>) Bitwise Operator in JavaScript

Improve
Improve
Like Article
Like
Save
Share
Report

JavaScript Zero Fill Right Shift Operator or Unsigned Right Shift Operator(>>>) is used for operating on the two operands. The first operand is the number and the right operand specifies the bits to shift towards the right modulo 32. In this way, the excess bits which are shifted towards the right are discarded and zero bits are added towards the left, as a result, the sign bit is now zero and the number becomes positive always.

Let’s look at the table below to better understand the output of the Zero Fill Right Shift Operation.

A 6 ( 00000000000000000000000000000110 )
B 1 ( 00000000000000000000000000000001 )
OUTPUT ( A >>> B ) 3 ( 00000000000000000000000000000011 )

Syntax:

a>>>b

Example 1: In this example, we will use the unsigned right shift operator on the numbers.

Javascript




let a = 4;
let b = -1
console.log(a>>>1);
console.log(b>>>4);


Output: The output will never be negative for any number

2
268435455

Example 2: In this example, we will use the unsigned right shift operator on Data Types that are not Number.

Javascript




let a = "HEllo";
let b =true;
let c = null;
console.log(a>>>1);
console.log(b>>>1);
console.log(c>>>1);


Output: The output of the unsigned right shift operator on non numbers will be zero.

0
0
0

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

We have a complete list of JavaScript Bitwise Operators, to check those please go through, the JavaScript Bitwise Operators article


Last Updated : 23 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads