Bit inversion: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>SPAAAAACE
Mentioned its use in computing (often as a "~" symbol). Added more citations and see also links.
 
imported>Frap
 
Line 1: Line 1:
In [[computing]] and [[telecommunications]], '''bit inversion''' means the changing of the state of a [[bit]] or [[binary number]] to the opposite state, i.e. the changing of a 0 bit to 1 or of a 1 bit to 0.<ref>{{Cite web |date=2023-08-15 |title=Bitwise NOT (~) - JavaScript {{!}} MDN |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT |access-date=2023-10-17 |website=developer.mozilla.org |language=en-US}}</ref><ref>{{Cite web |date=2023-04-11 |title=%BITNOT (Invert Bits) |url=https://www.ibm.com/docs/en/i/7.3?topic=functions-bitnot-invert-bits |access-date=2023-10-17 |website=www.ibm.com |language=en-us}}</ref><ref>{{Cite web |date=2018-05-18 |title=Invert actual bits of a number |url=https://www.geeksforgeeks.org/invert-actual-bits-number/ |access-date=2023-10-17 |website=GeeksforGeeks |language=en-US}}</ref> It is often represented with a [[tilde]] (~).<ref>{{Cite web |title=~ - Arduino Reference |url=https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitwisenot/ |access-date=2023-10-17 |website=www.arduino.cc}}</ref> It also refers to the changing of a ''state representing a given bit'' to the opposite state.
{{Short description|Computing term meaning changing the state of a bit}}
 
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.<ref>{{Cite web |date=2023-08-15 |title=Bitwise NOT (~) - JavaScript {{!}} MDN |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT |access-date=2023-10-17 |website=developer.mozilla.org |language=en-US}}</ref><ref>{{Cite web |date=2023-04-11 |title=%BITNOT (Invert Bits) |url=https://www.ibm.com/docs/en/i/7.3?topic=functions-bitnot-invert-bits |access-date=2023-10-17 |website=www.ibm.com |language=en-us}}</ref><ref>{{Cite web |date=2018-05-18 |title=Invert actual bits of a number |url=https://www.geeksforgeeks.org/invert-actual-bits-number/ |access-date=2023-10-17 |website=GeeksforGeeks |language=en-US}}</ref> It is often represented with a [[tilde]] (~).<ref>{{Cite web |title=~ - Arduino Reference |url=https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitwisenot/ |access-date=2023-10-17 |website=www.arduino.cc}}</ref> It also refers to the changing of a ''state representing a given bit'' to the opposite state.
 
==Usage in computing==
 
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:
 
<syntaxhighlight lang="javascript">
var a = 2;
var b = ~ a;
</syntaxhighlight>
 
In this example, a is a 32-bit [[signedness|signed]] integer and in binary would be 00000000000000000000000000000010. Variable {{Var|b}} is the bit inversion of variable {{Var|a}} and equals 11111111111111111111111111111101 (−3 in decimal).
 
In [[Python (programming language)|Python]]:
<syntaxhighlight lang="pycon">
>>> a = 2
>>> b = ~ a
>>> b
-3
</syntaxhighlight>


== References ==
== References ==
<references />
{{Reflist}}


== See also ==
== See also ==
Line 14: Line 35:




{{Telecomm-stub}}
{{Telecom-stub}}

Latest revision as of 19:09, 25 August 2025

Template:Short description

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

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 Template:Var is the bit inversion of variable Template:Var and equals 11111111111111111111111111111101 (−3 in decimal).

In Python:

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

References

Template:Reflist

See also

Template:Sister project


Template:Asbox

  1. Script error: No such module "citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "citation/CS1".
  4. Script error: No such module "citation/CS1".