@Test public void hexToLong() { String traceIdOrig; String traceIdResult; Random rand = new Random(); BigInteger traceIdNum; for (int i = 0; i < 10; i++) { traceIdNum = new BigInteger(64, 100, rand); traceIdOrig = traceIdNum.toString(16); long id = CommonUtils.hexToLong(traceIdOrig); traceIdResult = String.format("%x", id); assertEquals(traceIdOrig, traceIdResult); } }
public static long hexToLong(String hexString) { int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " + hexString); } if (length > LONG_HEX_STRING_BYTES) { throw new IllegalArgumentException( "Malformed id(length must be less than 2 times lengh of type long): " + hexString); } int charLast = length - 1; long result = 0; int i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } return result; }
CommonUtils { public static long hexToLong(String hexString) { int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " + hexString); } if (length > LONG_HEX_STRING_BYTES) { throw new IllegalArgumentException( "Malformed id(length must be less than 2 times lengh of type long): " + hexString); } int charLast = length - 1; long result = 0; int i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } return result; } }
CommonUtils { public static long hexToLong(String hexString) { int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " + hexString); } if (length > LONG_HEX_STRING_BYTES) { throw new IllegalArgumentException( "Malformed id(length must be less than 2 times lengh of type long): " + hexString); } int charLast = length - 1; long result = 0; int i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } return result; }  }
CommonUtils { public static long hexToLong(String hexString) { int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " + hexString); } if (length > LONG_HEX_STRING_BYTES) { throw new IllegalArgumentException( "Malformed id(length must be less than 2 times lengh of type long): " + hexString); } int charLast = length - 1; long result = 0; int i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } return result; }  static T parseNum(T num, T defaultInt); static long[] hexToDualLong(String hexString); static long hexToLong(String hexString); static boolean isHexString(String str); }
CommonUtils { public static long hexToLong(String hexString) { int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " + hexString); } if (length > LONG_HEX_STRING_BYTES) { throw new IllegalArgumentException( "Malformed id(length must be less than 2 times lengh of type long): " + hexString); } int charLast = length - 1; long result = 0; int i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } return result; }  static T parseNum(T num, T defaultInt); static long[] hexToDualLong(String hexString); static long hexToLong(String hexString); static boolean isHexString(String str);  }