Skip to content

Commit b5a5613

Browse files
committed
Bin, hex
1 parent d26a83f commit b5a5613

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ String
286286
<list> = textwrap.wrap(<str>, width) # Nicely breaks string into lines.
287287
```
288288

289-
```python
290-
<str> = bin(<int>) # Binary representation starting with '0b'.
291-
<str> = hex(<int>) # Hexadecimal representation starting with '0x'.
292-
```
293-
294289
### Char
295290
```python
296291
<str> = chr(<int>) # Converts int to unicode char.
@@ -445,6 +440,14 @@ from random import random, randint, choice, shuffle
445440
shuffle(<list>)
446441
```
447442

443+
### Bin, Hex
444+
```python
445+
<int> = 0b<bin> # Or: 0x<hex>
446+
<int> = int('0b<bin>', 0) # Or: int('0x<hex>', 0)
447+
<int> = int('<bin>', 2) # Or: int('<hex>', 16)
448+
'0b<bin>' = bin(<int>) # Or: '0x<bin>' = hex(<int>)
449+
```
450+
448451

449452
Combinatorics
450453
-------------

index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,6 @@ <h2 id="string"><a href="#string" name="string">#</a>String</h2>
389389
<pre><code class="python language-python hljs">&lt;bool&gt; = &lt;str&gt;.isnumeric() <span class="hljs-comment"># True if str contains only numeric characters.</span>
390390
&lt;list&gt; = textwrap.wrap(&lt;str&gt;, width) <span class="hljs-comment"># Nicely breaks string into lines.</span>
391391
</code></pre>
392-
<pre><code class="python language-python hljs">&lt;str&gt; = bin(&lt;int&gt;) <span class="hljs-comment"># Binary representation starting with '0b'.</span>
393-
&lt;str&gt; = hex(&lt;int&gt;) <span class="hljs-comment"># Hexadecimal representation starting with '0x'.</span>
394-
</code></pre>
395392
<h3 id="char">Char</h3>
396393
<pre><code class="python language-python hljs">&lt;str&gt; = chr(&lt;int&gt;) <span class="hljs-comment"># Converts int to unicode char.</span>
397394
&lt;int&gt; = ord(&lt;str&gt;) <span class="hljs-comment"># Converts unicode char to int.</span>
@@ -503,6 +500,12 @@ <h3 id="random">Random</h3>
503500
&lt;el&gt; = choice(&lt;list&gt;)
504501
shuffle(&lt;list&gt;)
505502
</code></pre>
503+
<h3 id="binhex">Bin, Hex</h3>
504+
<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>
505+
&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>
506+
&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>
507+
<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>
508+
</code></pre>
506509
<h2 id="combinatorics"><a href="#combinatorics" name="combinatorics">#</a>Combinatorics</h2>
507510
<ul>
508511
<li><strong>Every function returns an iterator.</strong></li>

0 commit comments

Comments
 (0)