> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/grammar/op/arithmetic/bitwise.md).

# bitwise operator

[JS](/web/js.md) ⟩ [statement](/web/js/grammar/statement.md) ⟩ [expression](/web/js/grammar/statement/expr.md) ⟩ [operator](/web/js/grammar/op.md) ⟩ [arithmetic](/web/js/grammar/op/arithmetic.md) ⟩ bitwise

{% hint style="success" %}

* bitwise and (&), or (|), xor (^), [**not (\~)**](/web/js/grammar/op/arithmetic/bitwise/not.md)
* shift left (<<), right (>>), right with 0 fill (>>>)

```javascript
~x    // invert bits (convert to number, = -x - 1)
```

these operators <mark style="color:yellow;">**convert**</mark> their operand to <mark style="color:blue;">**32**</mark><mark style="color:red;">**-bit**</mark>**&#x20;**<mark style="color:yellow;">**integers**</mark>:exclamation:

:star2: [table of operators](/web/js/grammar/op/table-of-operators.md)
{% endhint %}

{% tabs %}
{% tab title="🔴 主題" %}

* <mark style="color:yellow;">**bitwise operators**</mark>
  * :heavy\_plus\_sign: bitwise and (&) <mark style="color:yellow;">**/**</mark> or (|) <mark style="color:yellow;">**/**</mark> xor (^) <mark style="color:yellow;">**/**</mark> [bitwise not (\~)](/web/js/grammar/op/arithmetic/bitwise/not.md)
  * :heavy\_plus\_sign: shift left (<<) <mark style="color:yellow;">**/**</mark> right (>>) <mark style="color:yellow;">**/**</mark> right with 0 fill (>>>)
* <mark style="color:yellow;">**related topics**</mark>
  * :bulb: [2's complement](/web/js/grammar/op/arithmetic/bitwise/2s-complement.md) (<mark style="color:blue;">**`-x = ~x + 1`**</mark>)
  * :beginner: [double tilde (\~\~)](/web/js/grammar/op/arithmetic/bitwise/not/double-tilde.md) - nearest integer towards 0.
* <mark style="color:yellow;">**tools**</mark>
  * :floppy\_disk: [bitview()](/web/js/grammar/op/arithmetic/bitwise/bitview.md) - 32-bit representation of signed integers.
    {% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="warning" %} <mark style="color:purple;">**bitwise operator**</mark>&#x20;

* [<mark style="color:blue;">**NaN**</mark>](/web/js/val/prim/num/special/nan.md), <mark style="color:yellow;">**±**</mark>[<mark style="color:blue;">**Infinity**</mark>](/web/js/val/prim/num/special/infinity.md) <mark style="color:red;">**all**</mark> <mark style="color:yellow;">**converts**</mark> to <mark style="color:red;">**0**</mark>:exclamation:
* <mark style="color:yellow;">**all**</mark> (<mark style="color:red;">**except**</mark>**&#x20;**<mark style="color:purple;">**>>>**</mark>) <mark style="color:green;">**can**</mark>**&#x20;**<mark style="color:yellow;">**be used**</mark> with [Number](/web/js/val/prim/num.md) <mark style="color:yellow;">**/**</mark> [BigInt](/web/js/val/prim/bigint.md).
  {% endhint %}
  {% endtab %}

{% tab title="👥 相關" %}

* <mark style="color:purple;">**bitwise operators**</mark> [**convert**](/web/js/val/type/convert.md) their operands to <mark style="color:red;">**32-bit**</mark>**&#x20;**<mark style="color:yellow;">**integers**</mark>:exclamation:
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩ 4.8.3 Bitwise Operators
  {% endtab %}
  {% endtabs %}
