copy from :
http://www.adobe.com/devnet/flash/articles/bitwise_operators.html
|
Table 1. Combinational Operators | |||||||
|
|
Name |
Description |
Truth Table |
Examples | |||
|
A |
_ |
B |
= | ||||
|
& |
AND |
Sets the result bit to 1 only if both source bits are 1. |
0 |
& |
0 |
0 |
1001 & 1100 equals 1000 11 & 101 equals 1 (001) 0xF0F & 0xFF0 == 0xF00 |
|
0 |
& |
1 |
0 | ||||
|
1 |
& |
0 |
0 | ||||
|
1 |
& |
1 |
1 | ||||
|
| |
OR |
Sets the result bit to 1 if either of the source bits is 1. |
0 |
| |
0 |
0 |
1001 | 1100 equals 1101 11 | 101 equals 111 0xF0F & 0xFF0 == 0xFFF |
|
0 |
| |
1 |
1 | ||||
|
1 |
| |
0 |
1 | ||||
|
1 |
| |
1 |
1 | ||||
|
^ |
XOR |
Sets the result bit to 1 only if either, but not both, of the source bits is 1. Hence the name eXclusive OR. |
0 |
^ |
0 |
0 |
1001 | 1100 equals 1101 11 | 101 equals 111 0xF0F & 0xFF0 == 0x0FF |
|
0 |
^ |
1 |
1 | ||||
|
1 |
^ |
0 |
1 | ||||
|
1 |
^ |
1 |
0 | ||||
Other Operators
The operators in Table 2 all manipulate a single binary number.
|
Table 2. Other Operators | |||
|
|
Name |
Description |
Examples |
|
~ |
NOT |
Flips each bit. Ones become zeroes and zeroes become ones. |
~10010 equals 1101 (01101) ~111 equals 0 (000) ~0xF0F == 0xF0 (0x0F0) |
|
<< |
Left shift |
Shifts each bit the specified number of positions to the left, filling the new (least significant) positions with zeroes. |
10010 << 1 equals 100100 |
|
>> |
Right shift |
Shifts each bit the specified number of position to the right, discarding the rightmost (least significant) bits. |
10010 >> 1 equals 1001 10010 >> 2 equals 100 0xF0F >> 2 == 0xF |
컬러채널마스크
var argb:Number = 0xFFC97B33;
// isolate Alpha:
// leave bits in alpha channel alone, zero others
var alphaMask:Number = 0xFF000000;
var alpha:Number = argb & alphaMask;
"trace("Alpha: "+alpha.toString(16));
// isolate Red:
var redMask:Number = 0x00FF0000;
var red:Number = argb & redMask;
trace("Red: "+red.toString(16));
// isolate Green:
var greenMask:Number = 0x0000FF00;
var green:Number = argb & greenMask;
trace("Green: "+green.toString(16));
// isolate Blue:
var blueMask:Number = 0x000000FF;
var blue:Number = argb & blueMask;
trace("Blue: "+blue.toString(16));
** alpha 값이 -1000000 로 나오는데, 이는 플래시가 비트연산을 할때 integer 값을 사용하기 때문이다.
int.MAX_VALUE 값을 보면 0x7FFFFFF 임을 알 수 있다.
0xFF000000 값을 int에 담지 못하고 음수방향으로 거꾸로 더해져서 -1000000이 되는 것이다.
컬러 채널 값 얻기
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));
// isolate Red:
var red:Number = (argb & 0x00FF0000) >>> 16;
trace("Red: "+red.toString(16));
// isolate Green:
var green:Number = (argb & 0x0000FF00) >>> 8;
trace("Green: "+green.toString(16));
// isolate Blue:
var blue:Number = argb & 0x000000FF;
trace("Blue: "+blue.toString(16));
** '>>>' unsigned right shift 연산자를 이용해 음수가 나오는 경우를 방지할 수 있다.
컬러채널 합치기.
컬러채널 넣기
빠른 Math.floor
trace(1224.215>>0); // 1224





