Browse Source

Bitwise operators

pull/36/head
Jure Šorn 5 years ago
parent
commit
67f420db72
2 changed files with 20 additions and 2 deletions
  1. 12
      README.md
  2. 10
      index.html

12
README.md

@ -445,7 +445,17 @@ shuffle(<list>)
<int> = 0b<bin> # Or: 0x<hex> <int> = 0b<bin> # Or: 0x<hex>
<int> = int('0b<bin>', 0) # Or: int('0x<hex>', 0) <int> = int('0b<bin>', 0) # Or: int('0x<hex>', 0)
<int> = int('<bin>', 2) # Or: int('<hex>', 16) <int> = int('<bin>', 2) # Or: int('<hex>', 16)
'0b<bin>' = bin(<int>) # Or: '0x<bin>' = hex(<int>)
'0b<bin>' = bin(<int>) # Or: '0x<hex>' = hex(<int>)
```
### Bitwise Operators
```python
<int> = <int> & <int> # And
<int> = <int> | <int> # Or
<int> = <int> ^ <int> # Xor (0 if both bits equal)
<int> = <int> << n_bits # Shift left
<int> = <int> >> n_bits # Shift right
<int> = ~<int> # Compliment (flips bits)
``` ```

10
index.html

@ -504,7 +504,15 @@ shuffle(&lt;list&gt;)
<pre><code class="python language-python hljs">&lt;int&gt; = <span class="hljs-number">0</span>b&lt;bin&gt; <span class="hljs-comment"># Or: 0x&lt;hex&gt;</span> <pre><code class="python language-python hljs">&lt;int&gt; = <span class="hljs-number">0</span>b&lt;bin&gt; <span class="hljs-comment"># Or: 0x&lt;hex&gt;</span>
&lt;int&gt; = int(<span class="hljs-string">'0b&lt;bin&gt;'</span>, <span class="hljs-number">0</span>) <span class="hljs-comment"># Or: int('0x&lt;hex&gt;', 0)</span> &lt;int&gt; = int(<span class="hljs-string">'0b&lt;bin&gt;'</span>, <span class="hljs-number">0</span>) <span class="hljs-comment"># Or: int('0x&lt;hex&gt;', 0)</span>
&lt;int&gt; = int(<span class="hljs-string">'&lt;bin&gt;'</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Or: int('&lt;hex&gt;', 16)</span> &lt;int&gt; = int(<span class="hljs-string">'&lt;bin&gt;'</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Or: int('&lt;hex&gt;', 16)</span>
<span class="hljs-string">'0b&lt;bin&gt;'</span> = bin(&lt;int&gt;) <span class="hljs-comment"># Or: '0x&lt;bin&gt;' = hex(&lt;int&gt;)</span>
<span class="hljs-string">'0b&lt;bin&gt;'</span> = bin(&lt;int&gt;) <span class="hljs-comment"># Or: '0x&lt;hex&gt;' = hex(&lt;int&gt;)</span>
</code></pre>
<h3 id="bitwiseoperators">Bitwise Operators</h3>
<pre><code class="python language-python hljs">&lt;int&gt; = &lt;int&gt; &amp; &lt;int&gt; <span class="hljs-comment"># And</span>
&lt;int&gt; = &lt;int&gt; | &lt;int&gt; <span class="hljs-comment"># Or</span>
&lt;int&gt; = &lt;int&gt; ^ &lt;int&gt; <span class="hljs-comment"># Xor (0 if both bits equal)</span>
&lt;int&gt; = &lt;int&gt; &lt;&lt; n_bits <span class="hljs-comment"># Shift left</span>
&lt;int&gt; = &lt;int&gt; &gt;&gt; n_bits <span class="hljs-comment"># Shift right</span>
&lt;int&gt; = ~&lt;int&gt; <span class="hljs-comment"># Compliment (flips bits)</span>
</code></pre> </code></pre>
<h2 id="combinatorics"><a href="#combinatorics" name="combinatorics">#</a>Combinatorics</h2> <h2 id="combinatorics"><a href="#combinatorics" name="combinatorics">#</a>Combinatorics</h2>
<ul> <ul>

Loading…
Cancel
Save