[Q#7437987][A#7438009] How to convert binary string value to decimal
https://stackoverflow.com/q/7437987
How to convert a binary String such as to the value in decimal in Java? (expected result in the example is 50)
Answer
https://stackoverflow.com/a/7438009
Use Integer.parseInt (see javadoc), that converts your String to int using base two:
APIzation
int decimalValue = Integer.parseInt(c, 2);
package com.stackoverflow.api;
public class Human7438009 {
public static int convertBinaryStringToDecimal(String c) {
return Integer.parseInt(c, 2);
}
}
package com.stackoverflow.api;
/**
* How to convert binary string value to decimal
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/7438009">https://stackoverflow.com/a/7438009</a>
*/
public class APIzator7438009 {
public static int convertValue(String c) throws Exception {
return Integer.parseInt(c, 2);
}
}