Bitwise Right Shift Assignment (>>=) Expression Summary Perform a sign-propagating right shift by the specified amount and assign the value back to a variable. Syntax variable >>= amount Parameters variable The variable, property, or array element to update. amount The amount to shift the bits. The amount can be any valid expression. Description For numeric variables, the >>= operator computes the value of the expression on the right, and then shifts the bits of the variable, property, or array element value on the left by the specified amount. The expression on the right is the amount to shift the bits and is evaluated first. The shifted amount is assigned back to the variable on the left. The >>= operator is equivalent to the >> operator with the left-hand side being the variable, property, or array element to modify and the right-hand side being the amount to shift the bits. Therefore, the following expressions are equivalent: 12x >>= 5; // Equivalent to x = x >> 5x = x >> 5; // Equivalent to x >>= 5 How Bitwise Sign-propagating Right Shift Operations Work In a bitwise sign-propagating right shift operation, the value to shift is converted to its binary representation. For example, the decimal (base 10) number 0 (zero) may be converted to the binary form 0000 and the number 1 (one) may be converted to 0001. The bitwise sign-propagating right shift operation will move each bit to the right by the specified amount. For example, if we shift the base 10 number 4 (four) to the right by 2 (two), the operation looks like: 1230100 (4)--------0001 (1) // 4 >> 2 In this case, the base 10 number 1 (one) is produced by shifting the base 10 number 4 (four) to the right by two. Copies of the leftmost bit are added to the left, and excess bits on the right that were shifted off are discarded. Since the leftmost bit (the sign bit) is copied and added to the left, the sign is preserved. Thus, this operation is known as "sign-propagating". As an example, consider a sign-propagating right shift on the value -9 by 2: 12311111111111111111111111111110111 (-9)----------------------------------------------------------------11111111111111111111111111111101 (-3) // -9 >> 2 Differences from JavaScript Bitwise right shift operations are not limited to 32-bit integers in JS++. Unimplemented In JavaScript, the bitwise right shift operation is limited to signed 32-bit integers. Examples Basic Usage 123456import System; int x = 8;Console.log(x); // 8x >>= 2;Console.log(x); // 2 Division by 2 using Bitwise Right Shifts 12345678import System; int x = 8;Console.log(x); // 8x >>= 1;Console.log(x); // 4x >>= 1;Console.log(x); // 2 See Also Bitwise Right Shift Operator Bitwise Left Shift Assignment Operator Bitwise Unsigned Right Shift Assignment Operator External Links Arithmetic shift [Wikipedia] Share HTML | BBCode | Direct Link