How to use Bitwise NOT operator in Javascript

Description

The bitwise NOT is represented by a tilde (~) and returns the one's complement of the number.

Example


var num1 = 25;             //binary 00000000000000000000000000011001
var num2 = ~num1;          //binary 11111111111111111111111111100110
console.log(num2);               //-26

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions