(Bitwise Not) - MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference

Actionscript language reference
Table of Contents

Advertisement

~ (bitwise NOT)

Availability
Flash Player 5.
Usage
~ expression
Parameters
A number.
expression
Returns
A 32-bit integer.
Description
Operator (bitwise); also known as the one's complement operator or the bitwise complement
operator. Converts the
complement. That is, every bit that is a 0 is set to 1 in the result, and every bit that is a 1 is set to
0 in the result. The result is a signed 32-bit integer.
For example, the hex value 0x7777 is represented as this binary number:
0111011101110111
The bitwise negation of that hex value, ~0x7777, is this binary number:
1000100010001000
In hexadecimal, this is 0x8888. Therefore, ~0x7777 is 0x8888.
The most common use of bitwise operators is for representing flag bits (Boolean values packed
into 1 bit each).
Floating-point numbers are converted to integers by discarding any digits after the decimal point.
Positive integers are converted to an unsigned hex value with a maximum value of 4294967295 or
0xFFFFFFFF; values larger than the maximum have their most significant digits discarded when
they are converted so the value is still 32-bit. Negative numbers are converted to an unsigned hex
value via the two's complement notation, with the minimum being -2147483648 or
0x800000000; numbers less than the minimum are converted to two's complement with greater
precision and also have the most significant digits discarded.
The return value is interpreted as a two's complement number with sign, so the return value is an
integer in the range -2147483648 to 2147483647.
For more information, see "Operator precedence and associativity" in Using ActionScript in Flash.
Example
The following example demonstrates a use of the bitwise NOT (-) operator with flag bits:
var ReadOnlyFlag:Number = 0x0001;
// defines bit 0 as the read-only flag
var flags:Number = 0;
trace(flags);
68
Chapter 2: ActionScript Language Reference
to a 32-bit signed integer, and then applies a bitwise one's
expression

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents