binary_to_decimal.alc 510 B

1234567891011121314151617181920212223242526
  1. include "primitives.alh"
  2. Integer function b2d(param : String):
  3. Integer value
  4. value = 0
  5. Integer length
  6. length = string_len(param)
  7. Integer counter
  8. counter = integer_subtraction(length, 1)
  9. Integer accumul
  10. accumul = 1
  11. while (counter >= 0):
  12. if (string_get(param, counter) == "1"):
  13. value = integer_addition(value, accumul)
  14. accumul = integer_multiplication(accumul, 2)
  15. counter = integer_subtraction(counter, 1)
  16. return value!
  17. Void function main():
  18. while(True):
  19. output(b2d(input()))
  20. return!