List of usage examples for java.lang Integer toHexString
public static String toHexString(int i)
From source file:Main.java
public static String bytes2HexString(byte[] data) { if (data == null) { return null; }/* w w w .j a v a 2 s . c o m*/ StringBuilder sb = new StringBuilder(2 * data.length); for (byte b : data) { int n = 0x00ff & b; if (n < 10) { sb.append("0"); } sb.append(Integer.toHexString(n)); } return sb.toString(); }
From source file:Main.java
public static String MD5(String md5) { try {// w ww.j a v a 2 s . c o m MessageDigest md = MessageDigest.getInstance("MD5"); byte[] array = md.digest(md5.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { } return null; }
From source file:Main.java
public static char reverseToChar(int num) { /*/*w w w. j a v a 2s . c o m*/ * if (num == 10) return 'A'; else if (num == 11) return 'B'; else if * (num == 12) return 'C'; else if (num == 13) return 'D'; else if (num * == 14) return 'E'; else if (num == 15) return 'F'; else return * String.valueOf(num).charAt(0); */ return Integer.toHexString(num).charAt(0); }
From source file:Main.java
public static int[] getAntennaTestData(String rotation, String funCode) { List<Integer> dateItem = new ArrayList(); dateItem.add(Integer.valueOf(funCode)); int intStep = Integer.valueOf(rotation) * 10; String hexStep = Integer.toHexString(intStep); if (hexStep.length() < 4) { switch (hexStep.length()) { case 1:/*from ww w . j av a2 s . c o m*/ hexStep = "000" + hexStep; break; case 2: hexStep = "00" + hexStep; break; case 3: hexStep = "0" + hexStep; break; } } dateItem.add(Integer.valueOf(hexStep.substring(2, 4), 16)); dateItem.add(Integer.valueOf(hexStep.substring(0, 2), 16)); for (int i = 0; i < 6; i++) { dateItem.add(0); } int[] message = new int[dateItem.size()]; for (int i = 0; i < dateItem.size(); i++) { message[i] = dateItem.get(i); } return message; }
From source file:Main.java
/** * Convert byte array to hex string/*from w ww . j a v a 2s .com*/ * * @param bytes * @return */ public static String bytesToHex(byte[] bytes) { StringBuilder sbuf = new StringBuilder(); for (int idx = 0; idx < bytes.length; idx++) { int intVal = bytes[idx] & 0xff; if (intVal < 0x10) sbuf.append("0"); sbuf.append(Integer.toHexString(intVal).toUpperCase(Locale.US)); } return sbuf.toString(); }
From source file:Main.java
public static String sha256(String base) { try {/*from w w w . java2 s .c om*/ MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(base.getBytes("UTF-8")); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < hash.length; i++) { String hex = Integer.toHexString(0xff & hash[i]); if (hex.length() == 1) hexString.append('0'); hexString.append(hex); } return hexString.toString(); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static String md5(String input) { String res = ""; try {//from w w w . j a v a 2 s . c om MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(input.getBytes()); byte[] md5 = algorithm.digest(); String tmp = ""; for (int i = 0; i < md5.length; i++) { tmp = (Integer.toHexString(0xFF & md5[i])); if (tmp.length() == 1) { res += "0" + tmp; } else { res += tmp; } } } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return res; }
From source file:Main.java
public static String encode(String text) { try {//from ww w . java 2s. c o m MessageDigest digest = MessageDigest.getInstance("md5"); byte[] result = digest.digest(text.getBytes()); StringBuilder sb = new StringBuilder(); for (byte b : result) { int number = b & 0xff; String hex = Integer.toHexString(number); if (hex.length() == 1) { sb.append("0" + hex); } else { sb.append(hex); } } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String getDeviceID(Activity a) { TelephonyManager tm = (TelephonyManager) a.getApplicationContext() .getSystemService(Context.TELEPHONY_SERVICE); String id = tm.getDeviceId(); if (id == null) id = "DefaultTwitchUser"; return Integer.toHexString(id.hashCode()); }
From source file:Main.java
private static String getSessionComponent() { return Integer.toHexString((int) ((Math.random() + 1) * 0x10000)).substring(1); }