title: Program Binary Decimal Conversion 1
signature: func programBinaryDecimalConversion1(n string) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n string, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver("uEmIAgF", 0)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver("753310137", 20)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver("010011010", 154)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver("kNi", 0)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver("04562016903312", 130)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver("000111101", 61)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver("bk", 0)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver("9", 0)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver("1", 1)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver("XxT nXLlk", 0)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }