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.