Beetwise

Bitwise NOT

The NOT operation inverts every bit of one value.

A bit with the value 1 becomes 0, and a bit with the value 0 becomes 1.

The result depends on the bit width, because the width sets how many bits exist.

Try bitwise NOT in the bit editor

The result of NOT 5 in an 8-bit register. Edit the expression or select a bit to flip it.

7
6
5
4
3
2
1
0
-6
value · 8 bits · signed
hex
0xFA
Read the bits as

Bitwise NOT step by step

Calculate NOT 5 in an 8-bit register:

  1. Write the value in 8 bits: 00000101.
  2. Invert every bit: 11111010.
  3. The result is 250 as an unsigned value.
  4. The result is -6 as a signed value.

The truth table of NOT

The truth table of NOT
A~A
01
10

Where bitwise NOT is used

NOT builds an inverted mask, which then clears bits with AND.

The expression value &= ~mask is the standard way to clear a bit in C.

NOT is also the first step of a conversion into two’s complement.

Bitwise NOT: points to note

  • The bit width changes the result. NOT 5 gives 250 in 8 bits and 4294967290 in 32 bits.
  • Set the correct bit width before you invert a mask, or the mask clears the wrong bits.
  • In C, ~ is the bitwise NOT and ! is the logical NOT.

The full bit editor

The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.

Open this value in the full editor

Questions about bitwise NOT

What is NOT 5?
In an 8-bit register the result is 250, which is -6 as a signed value. In a 32-bit register the result is 4294967290.
Why does the bit width matter?
NOT inverts every bit of the register. A wider register has more bits to invert.
How do I clear a bit with NOT?
Invert the mask with NOT, then apply AND. In C this is value &= ~mask.