How do you convert A binary number to a BigInteger in Java?(如何在 Java 中将二进制数转换为 BigInteger?)
问题描述
我需要将一个非常大的二进制值转换为其十进制等效值.因为它是一个大整数,所以我使用的是 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中将二进制数转换为 BigInteger?
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
