Reverse of bytes to Hex program to convert Hex to bytes
<p>I am trying to write the reverse of the below program to get the bytes from the HEX value that i have. Finding it hard to do it. Any help?</p>

<pre><code>private static String bytesToHex(byte[] bytes) {
    char[] hexChars = new char [bytes.length *2];

    for (int i=0; i&lt; bytes.length; i++) {
        int v = bytes[i] &amp; 0xFF;
        hexChars[i*2] = HEX_ARRAY[v &gt;&gt;&gt;4];
        hexChars[i*2 + 1] = HEX_ARRAY[v &amp; 0x0F];

    }
    return new String(hexChars);
}
</code></pre>

<p>Consider HEX_ARRAY as char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();</p>

<p>I would prefer to do this python but even Java should be ok</p>

<p>Thanks for the help everyone. I resolved this by using </p>

<pre><code>import binascii
</code></pre>

<p><code>binascii.hexlify('data')</code></p>

<p>For the JAVA code I found the answer here:
<a href="https://github.com/EverythingMe/inbloom/blob/master/java/src/main/java/me/everything/inbloom/BinAscii.java" rel="nofollow">https://github.com/EverythingMe/inbloom/blob/master/java/src/main/java/me/everything/inbloom/BinAscii.java</a></p>

java python hex byte