binary_to_decimal.alc 519 B

123456789101112131415161718192021222324
  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 (integer_gte(counter, 0)):
  12. if (string_eq(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()))