# bitNot() Function & Examples

Use the bitNot() bitwise function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## bitNot

#### ~x

#### bitNot(x)

Try it yourself:

```calculio
~1
~2
bitNot([2, -3, 4])
```

---

## 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()](https://calcul.io/function/bitAnd/index.md) and an 8-bit mask: `bitAnd(bitNot(x), 255)`. Display the result with [bin()](https://calcul.io/function/bin/index.md). Use [bitOr()](https://calcul.io/function/bitOr/index.md) to set bits and [bitXor()](https://calcul.io/function/bitXor/index.md) 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.

[All functions](https://calcul.io/functions/index.md)
