Convert bytes To Hex String - Android java.lang

Android examples for java.lang:Byte Array

Description

Convert bytes To Hex String

Demo Code

public class Main {

  public static String bytesToHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
      String hex = Integer.toHexString(0xFF & bytes[i]);
      if (hex.length() == 1) {
        sb.append('0');
      }//from w  w w. jav  a  2 s .  c o  m
      sb.append(hex);
    }
    return sb.toString();
  }

}

Related Tutorials