public static int toDecimal(String binaryNumber) {
//write your code here
if(binaryNumber==null || binaryNumber.isEmpty())
{
return 0;
}
int decNo=0;
int temp=Integer.valueOf(binaryNumber);
for(int i=0;i<binaryNumber.length();i++)
{
int n=temp%10;
decNo=(int) (decNo+(n*(Math.pow(2, i))));
temp=temp/10;
}
return decNo;
}

package en.codegym.task.pro.task09.task0906;
/*
Binary converter
*/
public class Solution {
public static void main(String[] args) {
int decimalNumber = Integer.MAX_VALUE;
System.out.println("Decimal number " + decimalNumber + " is equal to binary number " + toBinary(decimalNumber));
String binaryNumber = "110011";
System.out.println("Binary number " + binaryNumber + " is equal to decimal number " + toDecimal(binaryNumber));
}
public static String toBinary(int decimalNumber) {
//write your code here
if(decimalNumber<=0)
{
return "";
}
String BinaryNo="";
int i=0;
int remender;
while (decimalNumber!=0)
{
remender=decimalNumber%2;
BinaryNo= Integer.toString(remender) +BinaryNo;
decimalNumber=decimalNumber/2;
i++;
}
return BinaryNo;
}
public static int toDecimal(String binaryNumber) {
//write your code here
if(binaryNumber==null || binaryNumber.isEmpty())
{
return 0;
}
int decNo=0;
int temp=Integer.valueOf(binaryNumber);
for(int i=0;i<binaryNumber.length();i++)
{
int n=temp%10;
decNo=(int) (decNo+(n*(Math.pow(2, i))));
temp=temp/10;
}
return decNo;
}
}

1111111111111111111111111111111". This resulted in a number format exception because 31 one's is WAY larger than the max an int can hold of2147483647. Anything larger than that max will result in the same exception.