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 - Our objective is to take a binary input and parse it, producing an int that accurately represents the corresponding binary number. In Java, the Integer.parseInt() method provides a straightforward way to convert a binary string into an integer.
Discussions

Java String to int binary number conversion - Stack Overflow
If 00111 is different from 111 then you can't store it as integers, you'll need to store them as strings. Note however, that even in binary, 001112 is equal to 1112. 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
[Help]Program to convert binary to integer
You can use a while loop or a do-while loop to ask if the user would like to enter another number. Prompt the user for 'Y' or 'N' and if the input read is 'Y', continue converting binary numbers. There's two ways of verifying the user input. You could use a for loop and iterate through every character in the number and check that all it's characters are '0' or '1'. OR You can just handle the exception thrown by Integer.parseInt(num, 2). If you get an exception, it means the number could not be parsed correctly. Edit: Also have your class names start with an uppercase character. More on reddit.com
๐ŸŒ r/javahelp
8
2
April 1, 2016
java - binary string to int - Stack Overflow
I have to convert binary string to integer. I can use & | . No exponentiation, no embedded functions. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 382697 โ€บ java โ€บ String-Binary-Integer
String to Binary to Integer (Java in General forum at Coderanch)
May 17, 2007 - Hi, since you have to handle 168 bits try java.math.BigInteger.BigInteger(String, int). Cheers, Oliver ยท reply reply ยท Bookmark Topic Watch Topic ยท New Topic ยท Boost this thread! Similar Threads ยท Ascii to binary and binary to ascii ยท Negative int ยท Reading a String backward ยท
๐ŸŒ
Dirask
dirask.com โ€บ posts โ€บ Java-convert-binary-String-to-int-QD9MzD
Java - convert binary String to int - Dirask
The best way to convert binary String to int in java is to use Integer.parseInt() method.
Find elsewhere
๐ŸŒ
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.

๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ convert-binary-string-to-int-java
Convert Binary String to Int in Java โ€” javathinking.com
A: In Java, numbers are stored in binary internally. Converting a binary string to an integer effectively gives you the binary representation in memory.
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ convert-binary-string-sequence-to-int-java
Convert Binary String Sequence to Int in Java โ€” javathinking.com
In Java, converting a binary string sequence to an integer is a common operation, especially in scenarios related to bitwise operations, data encoding, and digital signal processing. A binary string consists of only 0 and 1 characters, representing a binary number.
๐ŸŒ
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 second method internally calls the first method and converts the result to an Integer object. The String to convert must contain only digits, optionally with a plus or minus sign in front. These are allowed: ... Java has allowed the underscore as a digit separator since version 7, but only in numeric literals like 1_000 โ€“ for Integer.parseInt(), it remains an invalid character.
๐ŸŒ
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 - The โ€œbinary stringโ€ is a full 32 bits, 2^32-1 (4,294,967,295), and the Java int is a signed type with twoโ€™s complement , support values from -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647).
๐ŸŒ
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.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ examples โ€บ convert binary number to decimal and vice-versa
Java Program to Convert Binary Number to Decimal and ...
September 27, 2024 - Use the Integer.parseInt() method to convert the binary String to its decimal form, specifying the base of the number system (which is 2 for binary). ```java public class BinaryToDecimal { public static void main(String[] args) { String binaryString = "1101"; int decimal = Integer.parseInt...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ binary-to-decimal-conversion-in-java
Binary to Decimal Conversion in Java - GeeksforGeeks
If you are dealing with large binary value , try to use 'long' instead of 'int' to avoid any errors. In Java, the >> operator is a right shift operator. It shifts the bits of a number to the right, effectively dividing the number by 2 raised to the number of positions shifted. So, x >> y is roughly equivalent to x / (2^y) for non-negative integers.
Published: July 4, 2025
๐ŸŒ
Xojo Programming Forum
forum.xojo.com โ€บ general
Convert binary string to integer - General - Xojo Programming Forum
December 17, 2022 - I have a 4 byte string that was read from a fileโ€ฆ its binary value is โ€œ00 00 00 0Cโ€โ€ฆ How can I convert that into the integer 12? Thanks, Jim
๐ŸŒ
Study.com
study.com โ€บ business courses โ€บ business 104: information systems and computer applications
How to Convert String to Int in Java - ParseInt Method - Lesson | Study.com
January 9, 2023 - String q = new String("17"); int r = Integer.parseInt(q); System.out.println(r); The parseInt method can also accept a second parameter. It is called the radix, and it indicates the number base of the value.