1// Convert binary to decimal in java using recursion
2public class BinaryToDecimalRecursion
3{
4 static int binaryToDecimal(String strBinary, int a)
5 {
6 int size = strBinary.length();
7 if(a == size - 1)
8 return strBinary.charAt(a) - '0';
9 return((strBinary.charAt(a) - '0') << (size - a - 1)) + binaryToDecimal(strBinary, a + 1);
10 }
11 public static void main(String[] args)
12 {
13 String binaryNumber = "1111";
14 int n = 0;
15 System.out.println("Convert binary to decimal using recursion: ");
16 System.out.println(binaryToDecimal(binaryNumber, n));
17 }
18}