This is because -1 decimal equals 11111111111111111111111111111111 binary (thirty-two
1's), shifting right by one bit causes the least significant (bit farthest to the right) to be discarded
and the most significant bit to be filled in with 1. The result is
11111111111111111111111111111111 (thirty-two 1's) binary, which represents the 32-bit
integer -1.
See also
>>= (bitwise right shift and assignment)
>>= (bitwise right shift and assignment)
Availability
Flash Player 5.
Usage
expression1 =>>expression2
Parameters
expression1
expression2
Returns
Nothing.
Description
Operator (bitwise compound assignment); this operator performs a bitwise right-shift operation
and stores the contents as a result in
Example
The following two expressions are equivalent.
A >>= B
A = (A >> B)
The following commented code uses the bitwise (
bitwise operators.
function convertToBinary(number){
var result = "";
for (var i=0; i<32; i++) {
// Extract least significant bit using bitwise AND
var lsb = number & 1;
// Add this bit to our result string
result = (lsb ? "1" : "0") + result;
// Shift number right by one bit, to see next bit
number >>= 1;}
return result;
}
trace(convertToBinary(479));
// Returns the string 00000000000000000000000111011111
// The above string is the binary representation of the decimal
// number 479
264
Chapter 12: ActionScript Dictionary
A number or expression to be shifted left.
A number or expression that converts to an integer from 0 to 31.
expression1
.
) operator. It is also an example of using all
>>=
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers