all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

Bitwise Operators trouble


Bitwise Operators trouble jag57
12/28/2005 8:23:02 PM
flash actionscript: I have been following this tutorial -->
http://www.macromedia.com/devnet/flash/articles/bitwise_operators_04.html

In the second code block, Grant performs an AND operation using the values
argb and 0xFF000000 to extract the alpha component:

var argb:Number = 0xFFC97B33;
// mask the alpha bits, then shift them to the least significant bits
// shifting 6 hex digits, so 24 binary digits
var alpha:Number = (argb & 0xFF000000)>>24;
trace("Alpha: "+alpha.toString(16));

I was expecting the trace output to be: "Alpha: FF".

The result that was displayed was "Alpha: -1"

Can someone explain this?
Re: Bitwise Operators trouble kglad
12/28/2005 10:15:36 PM
Re: Bitwise Operators trouble kglad
12/28/2005 11:14:40 PM
Re: Bitwise Operators trouble jag57
12/29/2005 12:21:21 AM
I have found the solution here:
http://www.gskinner.com/blog/archives/2005/12/source_code_tra.html

If you look further down, Grant explains what's wrong.

This line:

var alpha:Number = (argb & 0xFF000000)>>24;

should be:

var alpha:Number = (argb & 0xFF000000)>>>24;

(notice 3 > are used instead of 2)
[quoted text, click to view]
Re: Bitwise Operators trouble Jeckyl
12/29/2005 9:58:21 AM
shift in flash seems to use sign-extending (there are two diff ways to shift
a number with the highest bit set .. depending on whether you think of the
bit pattern as a large positive number or a negative number)
--
Jeckyl

AddThis Social Bookmark Button