How to use Bitwise Signed Right Shift operator in Javascript

Description

The signed right shift is represented by two greater-than signs >> and shifts all bits in a 32-bit number to the right while preserving the sign.

Example

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


var oldValue = 64;               //equal to binary 1000000
var newValue = oldValue >> 5;    //equal to binary 10 which is decimal 2
console.log(newValue);

Javascript fills these empty bits with the value in the sign bit to create a complete number.

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions