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

int foo = Integer.parseInt("1001", 2);
Answer from Matt Ball on Stack Overflow
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ java โ€บ binary string to int java
How to Convert Binary String to Int in Java | Delft Stack
February 12, 2024 - If the binary string is valid, we print the decimal value to the console, which in this case is 18. In Java, the Math.pow() method serves as a key tool for manually converting a binary string into an integer.
Discussions

casting - java: convert binary string to int - Stack Overflow
I'm trying to convert a couple of binary strings back to int. However it doesn't convert all my binary strings, leaving me a java.lang.NumberFormatException exception. Here is my test code with 3 b... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert binary to string in Java
01001110 01101001 01100011 01100101 More on reddit.com
๐ŸŒ r/learnjava
16
7
April 1, 2018
java - binary string to int - Stack Overflow
Since it's homework, I intentionally leave the Java translation to the reader. It shouldn't be too hard, especially with the answer by Peter Lawrey in mind. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... New site design and philosophy for Stack Overflow: Starting February 24, 2026... ... Iโ€™m Jody, the Chief Product and Technology Officer at Stack Overflow, letโ€™s... 218 Converting an int to a binary string ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - How to convert binary string value to decimal - Stack Overflow
How to convert a binary String such as String c = "110010"; // as binary to the value in decimal in Java? (expected result in the example is 50) More on stackoverflow.com
๐ŸŒ stackoverflow.com
July 3, 2016
๐ŸŒ
Dirask
dirask.com โ€บ posts โ€บ Java-convert-binary-String-to-int-QD9MzD
Java - convert binary String to int - Dirask
public class Example3 { public ... String.format("%8s", binaryString); String withLeadingZeros = format.replace(' ', '0'); int backToNumber = Integer.parseInt(binaryString, 2); System.out.println(withLeadingZeros + " - " + backToNumber); ...
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ convert string to binary
Java โ€“ Convert String to Binary | mkyong.com
June 9, 2020 - For string a the binary string is 01100001. In Java, we can use Integer.parseInt(str, 2) to convert a binary string to a string.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 382697 โ€บ java โ€บ String-Binary-Integer
String to Binary to Integer (Java in General forum at Coderanch)
May 17, 2007 - This may sound stupid, but I am needing help parsing out a 168-bit "binary" stirng (it's a string, but it's just 0s and 1s). What I need to do is parse out certain portions of the string (using substring), and from those substrings, get an integer equivalent. Example: /***** String a = testData.substring(8, 38); // a = 001110101011000011010111011000 *****/ I want to convert 'a' to integer. Any help is appreciated. Thanks, B ... I don't know of anything in the java library that will do this for you, but if you'd like to try an implement a solution yourself this would be a good place to start.
Find elsewhere
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ convert a binary string to decimal in java
Convert a binary string to decimal in Java | Techie Delight
July 7, 2026 - To convert a base 2 string to a base 10 integer, you can use the overloaded version of the Integer#parseInt() method, which allows you to specify the radix. Following is a simple example demonstrating its usage to parse ...
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ convert-binary-string-sequence-to-int-java
Convert Binary String Sequence to Int in Java โ€” javathinking.com
For example, the string "102" is not a valid binary string. When the binary string represents a number larger than the maximum value of an int (i.e., 2^31 - 1), an overflow will occur if you use Integer.parseInt().
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ convert-bin-string-to-int-java
Converting Binary String to Integer in Java โ€” javathinking.com
In Java, integers are typically ... 0 and 1 characters that represents a binary number. For example, the binary string "101" represents the decimal number 5 because ......
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ convert-binary-string-to-int-java
Convert Binary String to Int in Java โ€” javathinking.com
In Java, there are often scenarios where you need to convert a binary string (a string consisting of only `0` and `1` characters) into an integer. This conversion can be useful in various applications, such as bitwise operations, data encoding, and digital signal processing.
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ [help]program to convert binary to integer
r/javahelp on Reddit: [Help]Program to convert binary to integer
April 1, 2016 -

I have to make a program that asks the user for a binary number then converts the binary number into a integer, then it'll ask the user if they would like to enter another number or not.

import java.util.Scanner;

class binary { public static void main(String args[]) { String num; char n; String repeat;

	Scanner in = new Scanner(System.in);
	System.out.println("Enter a binary number: ");
	num = in.nextLine();
	n = num.charAt(0);

	
	if (n != '1' && n != '0')
	{
		System.out.println("You did not enter a binary number..." +
			"try again: ");
		in.next();
	}
	else
	{
	System.out.println("Your binary number is " + Integer.parseInt(num,2));
	
}


}

}

Above is what i have so far, I am having trouble asking the user if they would like to enter another number or not and also verifying the user input is a little buggy as well. If you can help me or point me in the right direction that would be great, thanks in advance.

๐ŸŒ
HappyCoders
happycoders.eu โ€บ home โ€บ java โ€บ how to convert string to int in java โ€“ peculiarities and pitfalls
How to Convert String to Int in Java โ€“ Peculiarities and Pitfalls
2 weeks ago - The same binary or hexadecimal number thus leads โ€“ depending on whether it is stored in an int or in a long โ€“ to a different decimal number (if it is larger than Integer.MAX_VALUE). The following diagram shows the bit pattern of 0xCAFEBABE and its two readings: One bit pattern, two numbers: -889,275,714 as an int, 3,405,691,582 as a long ยท In the following section, weโ€™ll take a look at some more examples...
๐ŸŒ
javaspring
javaspring.net โ€บ blog โ€บ binary-to-int-java
Binary to Integer Conversion in Java โ€” javaspring.net
For example, the binary number ... integer. The range of values for an int is from (-2^{31}) to (2^{31}-1). The Integer.parseInt() method can be used to convert a binary string to an integer....
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-binary-to-decimal
Java Convert Binary to Decimal
Java Convert Binary to Decimal example and examples of string to int, int to string, string to date, date to string, string to long, long to string, string to char, char to string, int to long, long to int etc.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ convert negative binary to integer
Java โ€“ Convert negative binary to Integer | mkyong.com
June 2, 2020 - Review the following Java example to convert a negative integer in binary string back to an integer type. String binary = Integer.toBinaryString(-1); // convert -1 to binary // 11111111 11111111
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ convert integer to binary
Java โ€“ Convert Integer to Binary | mkyong.com
June 9, 2020 - "1" : "0"); } return result.toString(); } public static String printBinary(String binary, int blockSize, String separator) { List<String> result = new ArrayList<>(); int index = 0; while (index < binary.length()) { result.add(binary.substring(index, Math.min(index + blockSize, binary.length()))); index += blockSize; } return result.stream().collect(Collectors.joining(separator)); } }