Thursday, October 16, 2025
HomeLanguagesJavascriptNOT(~) Bitwise Operator in JavaScript

NOT(~) Bitwise Operator in JavaScript

JavaScript NOT(~) Operator is used to invert the bits of a number. The operator is represented by “~” symbol. It is a unary operator since it requires only one operand to operate. There are various uses of the Bitwise NOT operator which include bit-masking, finding two’s complement as well as error correction.

Let’s look at the truth table below to better understand the output of the NOR operation.

A OUTPUT ( ~A )
0 1
1 0

Syntax:

a ~ b

Example 1: In this example, we will perform basic NOT operation on Numbers.

Javascript




console.log(~24);
console.log(~10);
console.log(~-10);


Output:

-25
-11
9

Example 2: In this example, we will use the Bitwise NOT operator to find Two’s Complement of a number.

Javascript




function twoComplement(n) {
    let j = ~(n.toString(2)) + 1;
    return j;
}
console.log(twoComplement(2));
console.log(twoComplement(-2));


Output: To find the two’s complement we first convert the decimal number to binary then invert the bits using NOT Operator and add 1 afterward.

-10
10

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

We have a complete list of JavaScript Bitwise Operators, to check those please go through, the JavaScript Bitwise Operators article

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS