How to convert a Binary String to a base 10 integer in Java

前端 未结 9 1347
野性不改
野性不改 2020-11-27 14:30

I have an array of Strings that represent Binary numbers (without leading zeroes) that I want to convert to their corresponding base 10 numbers. Consider:

bi         


        
9条回答
  •  萌比男神i
    2020-11-27 15:13

    You need to specify the radix. There's an overload of Integer#parseInt() which allows you to.

    int foo = Integer.parseInt("1001", 2);
    

提交回复
热议问题