How to use the Bitwise NOT Calculator tool
- Enter the binary number to invert in Input A, for example 1100. This tool has a single input.
- Include leading zeros if the value belongs to a fixed-width register, such as 00001111 for a byte.
- Select Calculate to flip the bits, or Example to try 1100.
- Read the inverted bits in the Result box and select Copy to copy them.
What bitwise NOT does
NOT is a unary operation: it takes one operand and inverts it bit by bit. A 0 turns into 1 and a 1 turns into 0. No column affects another. The result is also called the ones' complement of the input, and applying NOT twice returns the original value.
Hardware does this with an inverter on each line of a bus. In C, Java, JavaScript and Python the operator is the tilde, as in ~x.
Word size: why leading zeros change the answer
The inverse of a number depends on how many bits the word has. This calculator uses exactly the digits you enter. NOT 1 is 0, NOT 0001 is 1110 and NOT 00000001 is 11111110. The three inputs are the same number, but they describe 1-bit, 4-bit and 8-bit words.
This differs from what many languages print. JavaScript converts the operand to a signed 32-bit integer, so ~5 is -6. Python integers have unlimited width, so ~5 is also -6. Both follow the identity ~x = -x - 1. To reproduce an 8-bit register here, type 00000101 and you get 11111010, which is 250 unsigned or -6 as a signed byte.
The field accepts 1 to 65,536 binary digits. Spaces and a 0b prefix are removed before inverting, so 1010 0101 returns 01011010 without the space. The inversion runs in your browser and the bits are not uploaded.
Bitwise NOT examples
Here are three inputs and their results, each inverted at the width typed.
The last pair inverts the subnet mask 255.255.255.0 to get the wildcard mask 0.0.0.255 used in router access control lists.
NOT 1100 = 0011
NOT 00001111 = 11110000
NOT 11111111111111111111111100000000
= 00000000000000000000000011111111NOT in masks and two's complement
NOT is most often paired with AND to clear bits. To clear bit 2 of a byte, invert the mask 00000100 to get 11111011, then AND the value with it. In C this is the idiom x &= ~mask.
NOT is also the first half of negation in two's complement: invert all bits, then add 1. The Binary Two's complement Converter on this site performs both steps at the width of its input.
Frequently asked questions
What is the bitwise NOT of 1100?
It is 0011. Each of the four bits is flipped: the two leading ones become zeros and the two trailing zeros become ones. In decimal terms, 12 becomes 3 in a 4-bit word.
Why does ~5 give -6 in JavaScript or Python and not 010?
Those languages treat the value as a signed two's complement integer, where inverting all bits of x yields -x - 1. This tool has no sign and no fixed 32-bit width. It inverts only the digits you typed, so 101 becomes 010.
Is bitwise NOT the same as ones' complement?
Yes. The ones' complement of a binary word is the word with every bit inverted, which is exactly what NOT produces. Two's complement is different: it is the ones' complement plus 1.
How do I invert a number as a 16-bit or 32-bit value?
Pad the input with leading zeros to 16 or 32 digits before selecting Calculate. The output width always matches the input width, so the padding zeros turn into leading ones in the result.
What is the difference between bitwise NOT and logical NOT?
Bitwise NOT, the tilde, inverts every bit and returns another number. Logical NOT, the exclamation mark operator in C-style languages, turns any nonzero value into false and zero into true. Only for a single bit do the two agree.
What happens if I enter digits other than 0 and 1?
The tool shows the message Enter between 1 and 65,536 binary digits and returns no result. Convert decimal or hex values to binary first, then invert them.