本文介紹了如何在 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!