我有一个字符串,其基数已被更改&它的价值被打印出来。有没有办法将字符串转换回原始形式?
我的代码如下:
String b=text2[i].toString(16);
此处text2
数组属于BigInteger
类型。我想从变量b
获取原始字符串。
答案 0 :(得分:1)
new BigInteger(b, 16).toString();
public static void main(String[] args) {
final BigInteger original = new BigInteger("27");
final String converted = original.toString(16);
final BigInteger convertedBack = new BigInteger(converted, 16);
System.out.println("original = [" + original.toString() + "]");
System.out.println("converted = [" + converted + "]");
System.out.println("convertedBack = [" + convertedBack.toString() + "]");
}
original = [27]
converted = [1b]
convertedBack = [27]