简体   繁体   中英

Convert base 2 to base 10

I'm trying to convert base 2 to base 10, but I keep getting:

"Value was either too large or too small for an Int64".

I use this code:

string number1 = Convert.ToString(Convert.ToInt64(numberBin1, 10));    

It shows the error even with reasonable values, like: 000111110100111101010000

Edit: Fixed thanks to Johnny and JSteward

在第二个参数ToInt64方法是fromBase ,你的情况应该是2。

long number = Convert.ToInt64("000111110100111101010000", 2));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM