Signed right shift 5 >> 1 0101 >> 1 0010 2
>>> Zero fill right shift 5 >>> 1 0101 >>> 1 0010 2
These examples appear to be same!I want to know difference between these two.
            Asked
            
        
        
            Active
            
        
            Viewed 50 times
        
    1
            
            
         
    
    
        Astha Jindal
        
- 19
- 2
1 Answers
1
            
            
        With >>>, 0s are shifted in from the left.
With >>, copies of the leftmost bit are shifted in from the left. If the leftmost bit is a 0, it'll be the same as >>>, but if the leftmost bit is a 1, it will be different. For example:
// in binary, -5 is represented as 111111111111... on the left
console.log(-5 >> 4);  // -5 >> 4 results in the left side still looking like 111111...
console.log(-5 >>> 4); // -5 >>> 4 shifts in 5 zeros: 000001111111...https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
 
    
    
        CertainPerformance
        
- 356,069
- 52
- 309
- 320