Bitwise operation - Zero fill right (>>>) is used?

Generally speaking, bit offset ( >> , <<) allows you to divide / multiply by^2

Example:

      9 (base 10): 00000000000000000000000000001001 (base 2)
                   --------------------------------
 9 >> 2 (base 10): 00000000000000000000000000000010 (base 2) 

= 2 (base 10)

For negative numbers:

Similarly, -9 >> 2it gives -3, because the sign is preserved:

     -9 (base 10): 11111111111111111111111111110111 (base 2)
                   --------------------------------
-9 >> 2 (base 10): 11111111111111111111111111111101 (base 2) = -3 (base 10)

But looking at >>>, which acts the same for positive numbers, m, but behaves differently for negative numbers:

mdn

Zero bits are shifted to the left.

I cannot find the reason / use for the offset 0on the left (which makes the integer positive) on the left:

       -9 (base 10): 11111111111111111111111111110111 (base 2)
                     --------------------------------
 -9 >>> 2 (base 10): 00111111111111111111111111111101 (base 2) = 1073741821 (base 10)

Question:

>>>? , - .

+4
2

, -, , .

, 8 32 , .

128 , , 1.

// Assume n is initialised to 0, so n = 00000000 in binary
n += 128;                    // now n = 10000000 in binary

→ > , , 8 "" 1 . , , 8 .


, , , . , , , / .

+3

32- (UInt32). → > 0, , UInt32 0, . .

enter image description here

:

function convert( arrayLikeVariable){
   // we dont know for sure if length is UInt32
   // e.g. arrayLikeVariable.length = "zavarakatranemia"
   // so we do >>> 0
   var len = arrayLikeVariable >>> 0 
   // Now len is UInt32 for sure. 
   [..]
   // code using the len
}

, . Polyfill :

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

+1

All Articles