我需要将一个非常大的二进制值转换为其十进制等效值.因为它是一个大整数,所以我使用的是 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模板网!
如何在 JTextPane 中的组件周围环绕文本?How to wrap text around components in a JTextPane?(如何在 JTextPane 中的组件周围环绕文本?)
MyBatis,如何获取插入的自动生成密钥?[MySql]MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何获取插入的自动生成密钥?[MySql])
在 Java 中插入 Oracle 嵌套表Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java:如何将 CLOB 插入 oracle 数据库Java: How to insert CLOB into oracle database(Java:如何将 CLOB 插入 oracle 数据库)
为什么 Spring-data-jdbc 不保存我的 Car 对象?Why does Spring-data-jdbc not save my Car object?(为什么 Spring-data-jdbc 不保存我的 Car 对象?)
使用线程逐块处理文件Use threading to process file chunk by chunk(使用线程逐块处理文件)