Skip to content

Instantly share code, notes, and snippets.

@stisa
Created August 19, 2017 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stisa/4e8ee25d012fbf60e8af055cc6959a7f to your computer and use it in GitHub Desktop.
Save stisa/4e8ee25d012fbf60e8af055cc6959a7f to your computer and use it in GitHub Desktop.
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