List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:Main.java
public static String bytesToHexString(byte[] src) { StringBuilder stringBuilder = new StringBuilder(""); if (src == null || src.length <= 0) { return null; }/*from w w w . j ava2 s . co m*/ for (int i = 0; i < src.length; i++) { int v = src[i] & 0xFF; String hv = Integer.toHexString(v); if (hv.length() < 2) { stringBuilder.append(0); } stringBuilder.append(hv); } return stringBuilder.toString().toUpperCase(); }
From source file:Main.java
public static String toBrowserHexValue(int number) { StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff)); while (builder.length() < 2) { builder.append("0"); }/*from w ww.j a v a2 s . c o m*/ return builder.toString().toUpperCase(); }
From source file:Main.java
public static String getHexStr(byte[] b) { StringBuilder builder = new StringBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(b); int i = 0;// w ww .j a v a2 s . c om while ((i = input.read()) != -1) { builder.append( Integer.toHexString(i).length() == 2 ? Integer.toHexString(i) : 0 + Integer.toHexString(i)); builder.append(" "); } return builder.toString(); }
From source file:Main.java
private static String convertToMac(byte[] mac) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { byte b = mac[i]; int value = 0; if (b >= 0 && b <= 16) { value = b;// w ww . j a v a 2 s. c om sb.append("0" + Integer.toHexString(value)); } else if (b > 16) { value = b; sb.append(Integer.toHexString(value)); } else { value = 256 + b; sb.append(Integer.toHexString(value)); } if (i != mac.length - 1) { sb.append(":"); } } return sb.toString(); }
From source file:Main.java
public static String byteArrayToHexString(byte[] b) { StringBuffer sb = new StringBuffer(b.length * 2); for (int i = 0; i < b.length; i++) { int v = b[i] & 0xff; if (v < 16) { sb.append('0'); }/*from w w w . j a v a2 s . c o m*/ sb.append(Integer.toHexString(v)); } return sb.toString().toUpperCase(); }
From source file:Main.java
public static String byteArrayToHexString(byte[] array) { StringBuffer hexString = new StringBuffer(); for (byte b : array) { int intVal = b & 0xff; if (intVal < 0x10) hexString.append("0"); hexString.append(Integer.toHexString(intVal)); }//from w w w . j ava 2 s .com return hexString.toString(); }
From source file:Main.java
public static void checkGLError(String op) { for (int error = GLES20.glGetError(); error != 0; error = GLES20.glGetError()) Log.e(LOGTAG, "After operation " + op + " got glError 0x" + Integer.toHexString(error)); }
From source file:Main.java
/** * byte 2 hex code/*from w ww. java2 s.c o m*/ * * @param bytes * @return */ private static String byte2Hex(byte[] bytes) { StringBuilder builder = new StringBuilder(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { String h = Integer.toHexString(bytes[i]); int l = h.length(); if (l == 1) h = "0" + h; if (l > 2) h = h.substring(l - 2, l); builder.append(h.toUpperCase()); if (i < (bytes.length - 1)) builder.append(':'); } return builder.toString(); }
From source file:Main.java
public static String binaryToHexString(byte[] messageDigest) { // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { int by = 0xFF & messageDigest[i]; if (by < 0x10) { hexString.append("0").append(Integer.toHexString(by)); } else if (by >= 0x10) { hexString.append(Integer.toHexString(by)); }//from ww w. j av a2 s.c o m } return hexString.toString(); }
From source file:Main.java
public static String hex2(int val) { String a = Integer.toHexString(val); if (a.length() < 2) { a = "0" + a; }/*from w ww. j a v a 2s. com*/ return a; }