Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Python

return hexadecimal representation of integer

def dec2hex(n):
    return "%X" % n
https://snipt.net/embed/6ae348bffd5515cb0e73e3f94e5b6db5/
https://snipt.net/raw/6ae348bffd5515cb0e73e3f94e5b6db5/
6ae348bffd5515cb0e73e3f94e5b6db5
python
Python
2
2016-12-10T04:41:54
True
False
False
/api/public/snipt/28373/
return-hexadecimal-representation-of-integer
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">dec2hex</span><span class="p">(</span><span class="n">n</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="s2">&quot;</span><span class="si">%X</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">n</span> </span></pre></div> </td></tr></table>
base, hex, python

Python

Convert a hexstring to an ASCII-String of optional XOR.

1
2
3
4
5
6
7
def hexstring2ascii(hexstring, xor=0):
    """ Convert a hexstring to an ASCII-String. If you like to XOR it, give the
        xor value as an integer. If not, leave it blank """
    ascii = ""
    for i in xrange(0, len(hexstring)/2):
        ascii = ascii + chr(int(hexstring[2*i:2*i+2],16)^xor) 
    return ascii
https://snipt.net/embed/db58bb40b5d5be5f5b56f8460f92054a/
https://snipt.net/raw/db58bb40b5d5be5f5b56f8460f92054a/
db58bb40b5d5be5f5b56f8460f92054a
python
Python
7
2016-12-08T00:02:52
True
False
False
/api/public/snipt/27926/
convert-a-hexstring-to-an-ascii-string-of-optional-xor
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">hexstring2ascii</span><span class="p">(</span><span class="n">hexstring</span><span class="p">,</span> <span class="n">xor</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="sd">&quot;&quot;&quot; Convert a hexstring to an ASCII-String. If you like to XOR it, give the</span> </span><span id="L-3"><a name="L-3"></a><span class="sd"> xor value as an integer. If not, leave it blank &quot;&quot;&quot;</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">ascii</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">hexstring</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">):</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">ascii</span> <span class="o">=</span> <span class="n">ascii</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">hexstring</span><span class="p">[</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="p">:</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">],</span><span class="mi">16</span><span class="p">)</span><span class="o">^</span><span class="n">xor</span><span class="p">)</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="n">ascii</span> </span></pre></div> </td></tr></table>
ascii, cipher, encoding, hex, python

PHP

PHP convert binary to hex

1
2
3
4
<?
//convert binary to hex
echo "bin2hex ".bin2hex("1")."\n";
?>
https://snipt.net/embed/150e181807d31b1bdce146433cf2a936/
https://snipt.net/raw/150e181807d31b1bdce146433cf2a936/
150e181807d31b1bdce146433cf2a936
php
PHP
4
2016-12-08T11:32:00
True
False
False
/api/public/snipt/8696/
php-convert-binary-to-hex
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">//convert binary to hex</span> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="s2">&quot;bin2hex &quot;</span><span class="o">.</span><span class="nb">bin2hex</span><span class="p">(</span><span class="s2">&quot;1&quot;</span><span class="p">)</span><span class="o">.</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
binary, hex, php
Copyrighted, illegal, or inappropriate content? Email [email protected].