Skip to content

Instantly share code, notes, and snippets.

@jfager
Created July 26, 2010 18:17
Show Gist options
  • Save jfager/490965 to your computer and use it in GitHub Desktop.
Save jfager/490965 to your computer and use it in GitHub Desktop.
public static String toLexiSortable(final double d) {
long tmp = Double.doubleToRawLongBits(d);
return toHexString('d', (tmp < 0) ? ~tmp : (tmp ^ SIGN_MASK));
}
public static double doubleFromLexiSortable(final String s) {
if (!s.startsWith("d")) {
throw new IllegalArgumentException(s
+ " does not represent a double");
}
long tmp = fromHexString(s);
tmp = (tmp < 0) ? (tmp ^ SIGN_MASK) : ~tmp;
return Double.longBitsToDouble(tmp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment