Created
August 19, 2017 13:32
-
-
Save stisa/4e8ee25d012fbf60e8af055cc6959a7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc itoa(n:int):string = | |
var num = if n<0: -n else: n | |
var i = 0 | |
result = "" | |
while num > 0: | |
result.add(char(48 + num mod 10)) | |
num = num div 10 | |
inc i # inc char count | |
if n < 0: | |
result.add('-') | |
inc i | |
num = 0 | |
i = i-1 | |
while num < i: | |
swap(result[num], result[i]) | |
dec i | |
inc num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment