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 it
The result of NOT 5 in an 8-bit register. Select a bit to change it. Change the bit width or the signed mode to see the effect.
Name or expression
ID0
ASCII
·
Binary
0b
0b11111010
Hex
0x
0xFA
Decimal
-6
Shift
Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·
Shift
Sign
Bits
Endian
7
6
5
4
3
2
1
0
Worked example
Calculate NOT 5 in an 8-bit register:
- Write the value in 8 bits: 00000101.
- Invert every bit: 11111010.
- The result is 250 as an unsigned value.
- The result is -6 as a signed value.
Where this 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.
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 tool
The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.
Open the full editorQuestions
- 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.