si la cadena comienza siempre con "0x" y es hexadecimal:
String str = "0x9999999999999999";
BigInteger number = new BigInteger(str.substring(2));
mejor, comprobar si se comienza con "0x"
String str = "0x9999999999999999";
BigInteger number;
if (str.startsWith("0x")) {
number = new BigInteger(str.substring(2), 16);
} else {
// Error handling: throw NumberFormatException or something similar
// or try as decimal: number = new BigInteger(str);
}
A la salida se como hexadecimal o convertir a una representación hexadecimal:
System.out.printf("0x%x%n", number);
// or
String hex = String.format("0x%x", number);
No estoy seguro de por qué hay un voto negativo, dado que el segundo ejemplo produce el pedido de producto OP, @Carlos es el único que sí lo hace. (Publicó más tarde) –
Esto tampoco considera los valores negativos – TheRealNeo
@TheRealNeo ¿Puede dar un ejemplo de un valor hexadecimal negativo que quiere decir? –