>我有一个字符串,其基数已更改并打印其值。有没有办法将字符串转换回其原始形式?
我的代码如下所示:
String b=text2[i].toString(16);
这里text2
数组是BigInteger
类型。我想从变量 b
中获取原始字符串。
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]