Bitwise NOT (~) Expression

Summary

Perform a bitwise logical negation operation.

Syntax

~ expression

Parameters

expression
Any legal numeric expression.

Description

For numeric expressions, the ~ operator computes the value of the operand, converts it to its equivalent binary representation, performs a bitwise NOT operation on it, and returns the evaluated result.

The bitwise NOT operation will invert each bit. Thus, a zero (0) bit will become one (1), and a one (1) bit will become zero (0). For example, here is an illustration of the evaluation of the expression ~5:

1
2
3
00000000000000000000000000000101 (5)
--------------------------------
11111111111111111111111111111010 (-6)

Differences from JavaScript

Logical NOT operations are not limited to 32-bit integers in JS++. Unimplemented In JavaScript, the logical NOT operation is limited to signed 32-bit integers.

Examples

indexOf
1
2
3
4
5
6
7
import System;
 
string foobar = "foobar";
 
if (~foobar.indexOf("foo")) {
    Console.log("'foo' was found inside 'foobar'");
}

See Also

Share

HTML | BBCode | Direct Link