Answers for "binary to decimal recursion java"

1

Convert binary to decimal in java using recursion

// Convert binary to decimal in java using recursion
public class BinaryToDecimalRecursion
{
   static int binaryToDecimal(String strBinary, int a) 
   {
      int size = strBinary.length(); 
      if(a == size - 1)
         return strBinary.charAt(a) - '0'; 
      return((strBinary.charAt(a) - '0') << (size - a - 1)) + binaryToDecimal(strBinary, a + 1); 
   }
   public static void main(String[] args) 
   {
      String binaryNumber = "1111"; 
      int n = 0;
      System.out.println("Convert binary to decimal using recursion: ");
      System.out.println(binaryToDecimal(binaryNumber, n));
   }
}
Posted by: Guest on February-18-2021

Code answers related to "binary to decimal recursion java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language