解析十六进制字符串以在 Java 中创建 BigInteger
要解析十六进制字符串以创建 BigInteger,可使用以下 BigInteger 构造函数,并将十六进制的基数设置为 16。
BigInteger(String val, int radix)
使用此构造函数可将指定基数的 BigInteger 字符串表示形式转换为 BigInteger。
在以下示例中,我们设置了 BigInteger,基数设置为 16 −
示例
import java.math.*; public class Demo { public static void main(String[] args) { BigInteger one, two; String hexStr = "290f98"; one = new BigInteger("250"); // parsing two = new BigInteger(hexStr, 16); System.out.println("Result (BigInteger) : " +one); System.out.println("Result (Parsing Hex String) : " +two); } }
Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.
输出
Result (BigInteger) : 250 Result (Parsing Hex String) : 2690968
广告