Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Java

Display ASCII code for every character in java string

1
2
3
String str = "Java practice session. "; 
for (int i=0; i<str.length();i++)
System.out.println(str.charAt(i) + " as ASCII value of: " + (int)str.charAt(i) );
https://snipt.net/embed/361c29f188361c18b151dc992e2542bd/
https://snipt.net/raw/361c29f188361c18b151dc992e2542bd/
361c29f188361c18b151dc992e2542bd
java
Java
3
2016-12-06T13:33:50
True
False
False
/api/public/snipt/34582/
display-ascii-code-for-every-character-in-java-string
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">String</span> <span class="n">str</span> <span class="o">=</span> <span class="s">&quot;Java practice session. &quot;</span><span class="o">;</span> </span><span id="L-2"><a name="L-2"></a><span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="o">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">str</span><span class="o">.</span><span class="na">length</span><span class="o">();</span><span class="n">i</span><span class="o">++)</span> </span><span id="L-3"><a name="L-3"></a><span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">str</span><span class="o">.</span><span class="na">charAt</span><span class="o">(</span><span class="n">i</span><span class="o">)</span> <span class="o">+</span> <span class="s">&quot; as ASCII value of: &quot;</span> <span class="o">+</span> <span class="o">(</span><span class="kt">int</span><span class="o">)</span><span class="n">str</span><span class="o">.</span><span class="na">charAt</span><span class="o">(</span><span class="n">i</span><span class="o">)</span> <span class="o">);</span> </span></pre></div> </td></tr></table>
ascii, character, java, string

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

Python

Sloppily convert all UTF values in a list to ASCII.

ascii_vals_list = map(str, list)
https://snipt.net/embed/3fe9b0aff696f6fa1d6198c39800fa52/
https://snipt.net/raw/3fe9b0aff696f6fa1d6198c39800fa52/
3fe9b0aff696f6fa1d6198c39800fa52
python
Python
1
2016-12-08T18:18:50
True
False
False
/api/public/snipt/22069/
sloppily-convert-all-utf-values-in-a-list-to-ascii
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">ascii_vals_list</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> </span></pre></div> </td></tr></table>
ascii, map, python

C

change the case of any ASCII character

1
2
3
4
# change the case of any ASCII character in C-based languages
uppercase = current & 0xFD; 
lowercase = current | 0x20; 
inverted_case = current ^ 0x20;
https://snipt.net/embed/f6b2385487332aaaee39b8924ced03cd/
https://snipt.net/raw/f6b2385487332aaaee39b8924ced03cd/
f6b2385487332aaaee39b8924ced03cd
c
C
4
2016-12-08T16:59:15
True
False
False
/api/public/snipt/22045/
change-the-case-of-any-ascii-character
<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"># change the case of any ASCII character in C-based languages</span> </span><span id="L-2"><a name="L-2"></a><span class="n">uppercase</span> <span class="o">=</span> <span class="n">current</span> <span class="o">&amp;</span> <span class="mh">0xFD</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="n">lowercase</span> <span class="o">=</span> <span class="n">current</span> <span class="o">|</span> <span class="mh">0x20</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="n">inverted_case</span> <span class="o">=</span> <span class="n">current</span> <span class="o">^</span> <span class="mh">0x20</span><span class="p">;</span> </span></pre></div> </td></tr></table>
ascii, case, conversion, text
Copyrighted, illegal, or inappropriate content? Email [email protected].