List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:Main.java
public static int randomRGB() { String r, g, b;//from ww w .jav a 2 s .c om Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexString(random.nextInt(256)).toUpperCase(); b = Integer.toHexString(random.nextInt(256)).toUpperCase(); r = r.length() == 1 ? "0" + r : r; g = g.length() == 1 ? "0" + g : g; b = b.length() == 1 ? "0" + b : b; return Color.parseColor("#" + (r + g + b)); }
From source file:Main.java
private static String byte2hex(byte[] bytes) { StringBuilder sign = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); }//from w w w . j av a 2 s .com sign.append(hex.toUpperCase()); } return sign.toString(); }
From source file:Main.java
public static String byteToHexString(byte[] b) { StringBuffer hexString = new StringBuffer(); for (int i = 0; i < b.length; i++) { String hex = Integer.toHexString(b[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; }/*from ww w . j a va2 s . c o m*/ hexString.append(hex.toUpperCase()); } return hexString.toString(); }
From source file:Main.java
public static String byte2hex(byte[] bytes) { StringBuilder sign = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); }//from w w w .j a va 2s.c o m sign.append(hex.toUpperCase()); } return sign.toString(); }
From source file:Main.java
public static String parseByte2HexStr(byte buf[]) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < buf.length; i++) { String hex = Integer.toHexString(buf[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; }// w w w . j a v a2 s. c o m sb.append(hex.toUpperCase()); } return sb.toString(); }
From source file:Main.java
public static String byte2hex(byte[] buffer) { String h = ""; for (int i = 0; i < buffer.length; i++) { String temp = Integer.toHexString(buffer[i] & 0xFF); if (temp.length() == 1) { temp = "0" + temp; }//from www. j a v a2 s . c o m h = h + " " + temp; } return h; }
From source file:Main.java
private static String bytes2hex(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0XFF); if (hex.length() == 1) { sb.append("0").append(hex); } else {/*from www . j a v a 2 s .c o m*/ sb.append(hex); } } return sb.toString(); }
From source file:Main.java
public static String toHexString(byte[] bytes) { StringBuilder sign = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); }/* w w w .java 2s .com*/ sign.append(hex); } return sign.toString(); }
From source file:Main.java
public static String bytesToHexString(byte[] bytes) { StringBuffer sb = new StringBuffer(); 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. j a v a2 s.c o m*/ sb.append(hex); } return sb.toString(); }
From source file:Main.java
private static String convertToHexString(byte[] array) { StringBuilder hexStr = new StringBuilder(); for (int i = 0; i < array.length; ++i) { hexStr.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); }/* w ww. ja va2 s . com*/ return hexStr.toString(); }