Posted By

alejandrosuch on 04/14/10


Tagged

hex byte


Versions (?)

Convert byte array to Hex String and vice versa


 / Published in: Java
 

  1. public static String getHexString(byte[] b) throws Exception {
  2. String result = "";
  3. for (int i=0; i < b.length; i++) {
  4. result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
  5. }
  6. return result;
  7. }
  8.  
  9. public static byte[] getByteArray(String hexString) {
  10. return BigInteger(hexString,16).toByteArray();
  11. }

Report this snippet  

You need to login to post a comment.