Bit inversion

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

In computing and telecommunications, bit inversion refers to the changing of the state of a bit or binary number to the opposite state, for example changing a 0 bit to 1 or vice versa.[1][2][3] It is often represented with a tilde (~).[4] It also refers to the changing of a state representing a given bit to the opposite state.

Usage in computing

[edit | edit source]

Many popular programming languages implement bit inversion as an operation. For example, in JavaScript, bit inversion is known as a 'bitwise NOT' and is implemented as seen below:

var a = 2;
var b = ~ a;

In this example, a is a 32-bit signed integer and in binary would be 00000000000000000000000000000010. Variable b is the bit inversion of variable a and equals 11111111111111111111111111111101 (−3 in decimal).

In Python:

>>> a = 2
>>> b = ~ a
>>> b
-3

References

[edit | edit source]
  1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).

See also

[edit | edit source]