JavaScript Unary Operators The bitwise NOT operator (~)


Example

The bitwise NOT (~) performs a NOT operation on each bit in a value.

Syntax:

~expression

Returns:

  • a Number.

Description

The truth table for the NOT operation is:

aNOT a
01
10
1337  (base 10) = 0000010100111001 (base 2)
~1337 (base 10) = 1111101011000110 (base 2) = -1338 (base 10)

A bitwise not on a number results in: -(x + 1).

Examples:

value (base 10)value (base 2)return (base 2)return (base 10)
20000001011111100-3
10000000111111110-2
00000000011111111-1
-111111111000000000
-211111110000000011
-311111100000000102