Convert byte array to Hex String and vice versa


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.