Bitwise NOT Calculator

Calculate ~A online and see how every bit flips inside the selected bit width.

Number A
Dec46 Hex0x2E

NOT Result

NOT (~A)
Dec0
Hex0x00
Bin00000000

Bit-by-Bit Visualization

1 Active bit 0 Diff bit 0 Included zero 0 Leading zero

NOT Truth Table

Click a row to load a value into A and inspect the NOT result.

Input ANOT A
01
10
Click a truth table row to test those values.

How the Bitwise NOT Calculator Works

A bitwise NOT calculator inverts every bit in the selected width. Because NOT depends on width, 8-bit, 16-bit, 32-bit, and 64-bit views can produce different displayed values.

NOT Rule

Each 1 becomes 0 and each 0 becomes 1 inside the chosen bit width.

Width Matters

A fixed width controls how many leading bits are included in the complement.

Signed View

Signed output uses two’s complement interpretation for negative integer checks.

Visual Flip

The bit grid shows every position that changes after the inversion.

Bitwise NOT Calculation Steps

Use these steps to calculate a bitwise complement.

Choose a Bit Width

  • Select 8, 16, 32, or 64 bits when width matters.
  • Use auto for quick unsigned inspection.
  • Pad the binary value to that width.

Invert Every Bit

  • Change each 1 to 0.
  • Change each 0 to 1.
  • Keep all included zeros inside the width.

Interpret the Result

  • Read the unsigned decimal output.
  • Switch to signed mode when checking two’s complement.
  • Use hex output for compact debugging.

Bitwise NOT Examples

NOT examples show why selected width affects the complement.

InputOperationResultUse
~00101110 8-bit NOT 11010001 Byte complement
~00001111 8-bit NOT 11110000 Nibble inversion
~0x2E 8-bit NOT 0xD1 Hex complement
~46 8-bit NOT 209 unsigned Width-limited decimal

Why Use This Bitwise NOT Calculator?

Use this NOT calculator when you need a clear complement result with fixed-width behavior.

Width-Aware Complement

See how ~A changes between 8, 16, 32, and 64 bits as more leading zeros flip.

Signed and Unsigned

Compare the unsigned complement with the signed two’s complement value, such as 209 and -47.

Hex Complement

Read the inverted pattern as hex, for example ~0x2E = 0xD1 at 8 bits.

Flip Visualisation

Every changed bit is highlighted in the grid so you can verify the inversion.

Practical Uses for Bitwise NOT

NOT is useful for complements, inverse masks, and two’s complement learning.

Clear a Flag

flags &= ~FLAG is the standard way to turn one bit off.

Two's Complement

Negation is ~x + 1, so ~x equals -(x + 1) in signed arithmetic.

All-Ones Masks

~0u produces a mask with every bit set at the type’s full width.

Truncation Idiom

In JavaScript, ~~x truncates a number to a 32-bit integer.

What the Bitwise NOT Operator Does

Bitwise NOT (~) is the only common bitwise operator that takes a single operand. It inverts every bit: each 1 becomes 0 and each 0 becomes 1. The operation is also called the one’s complement.

A~A
01
10

The catch is the phrase “every bit”. NOT also flips the leading zeros you normally don’t write down, so the result depends entirely on how many bits the value occupies. That is why this calculator asks for a bit width.

Why Bit Width Changes the Answer

Here is ~46 at three different widths:

WidthInput (binary)~Input (binary)UnsignedSigned
8-bit0010111011010001209−47
16-bit0000000000101110111111111101000165,489−47
32-bit0…001011101…110100014,294,967,249−47

The unsigned result changes with the width because more leading zeros turn into ones. The signed result is −47 every time. That isn’t a coincidence, and the next section explains it.

For an unsigned n-bit value, ~x = (2^n − 1) − x. At 8 bits that is 255 − 46 = 209. Subtracting from an all-ones number is exactly what flipping every bit does.

Why ~x Equals −(x + 1)

Almost every modern processor stores signed integers in two’s complement. In that system, the negative of x is computed by inverting all the bits and adding 1:

−x = ~x + 1

Rearranging gives the rule that surprises many developers:

~x = −x − 1 = −(x + 1)

So ~5 = −6, ~0 = −1, ~−1 = 0, and ~46 = −47. Languages that use signed integers by default, including Python, JavaScript, Java, and C with int, all follow this rule. If you expected ~5 to be 2 (flipping only the three bits of 101), you were thinking of a 3-bit unsigned value. Use the calculator’s 8-bit width and signed toggle to see both views side by side.

Using NOT to Build Inverse Masks

On its own, NOT is mostly used to invert a mask so AND can clear bits:

#define FLAG_DIRTY (1u << 2)       /* 00000100 */

flags &= ~FLAG_DIRTY;              /* ~FLAG_DIRTY = 11111011 */

The inverted mask has a 0 only at the flag’s position, so AND clears that one bit and keeps the others. This x & ~mask pattern is the standard “clear bit” operation in C, embedded firmware, and kernel code.

NOT also helps build ranges. ~0u is all ones at the full width of an unsigned int, and ~0u << 4 sets every bit except the low four. To keep the top bits and clear the low nibble, use x & ~0xFu.

Bitwise NOT in Python, JavaScript, and C

print(~46)              # -47
print(~46 & 0xFF)       # 209  (force an 8-bit unsigned view)
print(~0b101 & 0b111)   # 2    (3-bit view)

Python integers have unlimited width, so ~x is always negative for non-negative x. Mask with 0xFF, 0xFFFF, or 0xFFFFFFFF to get the fixed-width answer you see in this calculator.

console.log(~46);          // -47
console.log(~46 >>> 0);    // 4294967249 (32-bit unsigned view)
console.log(~~3.9);        // 3  (double NOT truncates to a 32-bit integer)
console.log(~"abc".indexOf("z")); // 0, a falsy "not found" idiom
#include <stdint.h>
uint8_t  a = 46;
uint8_t  b = (uint8_t)~a;   /* 209: cast back to 8 bits */
int      c = ~46;           /* -47 */

In C, ~a on a uint8_t first promotes a to int, so the raw result is -47. The cast to uint8_t keeps the low 8 bits and gives 209.

NOT Compared With Logical NOT and XOR

  • Logical NOT (! or not) turns any non-zero value into false and zero into true. !46 is 0 (false), while ~46 is −47.
  • XOR with all ones inverts only the bits inside the mask. x ^ 0xFF flips the low 8 bits and leaves the rest alone, which is often safer than ~x on wider types.
  • Negation (-x) is NOT plus one in two’s complement: -46 = ~46 + 1 = −47 + 1.

Common Mistakes With Bitwise NOT

  • Forgetting the width. ~0x0F is 0xF0 at 8 bits but 0xFFFFFFF0 at 32 bits.
  • Expecting a positive result in Python or JavaScript. Mask the result if you want the unsigned value.
  • Integer promotion in C. Smaller types are promoted to int before ~, so comparisons such as ~a == 0xD1 are false unless you cast.
  • Using ~ where ! was meant. if (~x) is true for every value except −1.

Frequently Asked Questions

Find answers to common questions about bitwise operations and this online tool.

What does bitwise NOT do?

Bitwise NOT (~) flips every bit of a single operand. Each 1 becomes 0 and each 0 becomes 1 across the full bit width.

Why does ~5 return -6?

Signed integers use two’s complement, where -x = ~x + 1. Rearranging gives ~x = -(x + 1), so ~5 = -6 and ~46 = -47.

Why does the NOT result depend on bit width?

NOT also flips leading zeros. At 8 bits, ~46 is 209 (11010001), but at 16 bits it is 65,489 because eight more zeros become ones.

How do I get an unsigned NOT result in Python?

Python integers have no fixed width, so mask the result: ~46 & 0xFF gives 209 for 8 bits and ~46 & 0xFFFFFFFF gives 4,294,967,249 for 32 bits.

What is the difference between ~ and ! ?

~ inverts every bit and returns an integer. ! is logical NOT and returns true or false. !46 is false, while ~46 is -47.

Is NOT the same as XOR with all ones?

Within the mask width, yes. x ^ 0xFF gives the same low 8 bits as ~x, but it leaves bits above the mask unchanged, which is often safer on wider types.