我需要将一个非常大的二进制值转换为其十进制等效值.因为它是一个大整数,所以我使用的是 BigInteger.那么如何将此二进制数转换为 BigInteger?
I needed to convert a very big binary value into its decimal equivalent. As it is a big integer I was using BigInteger. So how do I convert this binary number to a BigInteger?
如果你有二进制数的 String
表示,将它提供给这个重载的 BigInteger
构造函数以创建一个实例:
If you have the String
representation of your binary number, provide it to this overloaded BigInteger
constructor to create an instance:
BigInteger(String val, int radix);
在你的情况下,基数显然是 2,即你可以使用这样的东西:
In your case, radix is clearly 2, i.e. you can use something like this:
BigInteger yourNumber = new BigInteger("101000101110...1010", 2);
这篇关于如何在 Java 中将二进制数转换为 BigInteger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!