本文介紹了如何在 Java 中將二進(jìn)制數(shù)轉(zhuǎn)換為 BigInteger?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我需要將一個非常大的二進(jìn)制值轉(zhuǎn)換為其十進(jìn)制等效值.因?yàn)樗且粋€大整數(shù),所以我使用的是 BigInteger.那么如何將此二進(jìn)制數(shù)轉(zhuǎn)換為 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?
推薦答案
如果你有二進(jìn)制數(shù)的 String
表示,將它提供給這個重載的 BigInteger
構(gòu)造函數(shù)以創(chuàng)建一個實(shí)例:
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);
在你的情況下,基數(shù)顯然是 2,即你可以使用這樣的東西:
In your case, radix is clearly 2, i.e. you can use something like this:
BigInteger yourNumber = new BigInteger("101000101110...1010", 2);
這篇關(guān)于如何在 Java 中將二進(jìn)制數(shù)轉(zhuǎn)換為 BigInteger?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!