bitNot

~x

bitNot(x)

Try it yourself:


bitNot(): invert integer bits

bitNot(x) flips every bit of an integer: 0 becomes 1 and 1 becomes 0. It is the bitwise complement operation, often used when constructing masks or clearing selected flags.

How to reason about it

Unlike a fixed-width paper example, an integer calculator has a signed representation. Consequently, the complement of 0 is normally −1, and bitNot(5) is normally −6. This follows the familiar identity bitNot(x) = −x − 1 for two’s-complement integer semantics.

Masking safely

To invert only the low eight bits, combine a complement with bitAnd() and an 8-bit mask: bitAnd(bitNot(x), 255). Display the result with bin(). Use bitOr() to set bits and bitXor() when a toggle is what you need.

Care with inputs

Pass integers, not approximate decimal measurements. Always document the intended bit width when exchanging results with hardware, files, or APIs; otherwise leading sign bits can make a correct complement look surprising.

Try Bit Not in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions