Javascript - Bitwise Signed Right Shift

Introduction

The signed right shift operator is >> and shifts all bits to the right while preserving the sign bit.

A signed right shift is the exact opposite of a left shift.

For example, if 64 is shifted to the right five bits, it becomes 2:

var oldValue = 64;               //equal to binary 1000000 
var newValue = oldValue >> 5;    //equal to binary 10 which is decimal 2 
                                            The number 64 
 0   0   0  0   0   0  0   0  0   1   0  0   0   0  0   0 
The number 64 shifted to the right five bits (the number 2) 
 0   0   0  0   0   0  0   0  0   0   0  0   0   0  1   0 
Padded with zeros 

Related Topic