In digital electronics and software, we often meet the NOT function. The logic symbols for an electronic NOT gate are as follows:
The truth table for NOT is as follows:
In words, the output is always equal to the opposite state of the input A. Some observations about this:
We use this toggle all bits
This is not limited to single bits. In software, we often perform logical operations on integers (binary numbers). Consider the following example:
The NOT function is applied a decimal number. In the C or C++ programming language, this could be calculated as:
unsigned A = 170; //AA IN HEX A = ~A;
The result is 85 //55 IN HEX
This is sometimes known as a 1’s compliment. When we use 2’s compliment signed arithmetic, the inversion of bits is part of the process of changing the sign of a signed integer.