title: Program Binary Decimal Conversion 1
signature: program_binary_decimal_conversion_1 <- function(n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          "uEmIAgF", 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          "753310137", 
          20L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          "010011010", 
          154L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          "kNi", 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          "04562016903312", 
          130L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          "000111101", 
          61L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          "bk", 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          "9", 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          "1", 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          "XxT nXLlk", 
          0L
      )))
  
  }
  
  main()
source_py: def program_binary_decimal_conversion_1(n):
      num = n
      dec_value = 0
      base1 = 1
      len1 = len(num)
      for i in range((len1 - 1), (- 1), (- 1)):
          if (num[i] == '1'):
              dec_value += base1
          base1 = (base1 * 2)
      return dec_value
source_cpp: int program_binary_decimal_conversion_1(string n) {
    string num = n;
    int dec_value = 0;
    int base = 1;
    int len = num . length ( );
    for ( int i = len - 1;
    i >= 0;
    i -- ) {
      if ( num [ i ] == '1' ) dec_value += base;
      base = base * 2;
    }
    return dec_value;
  }