Skip to content

Instantly share code, notes, and snippets.

@kpmy
Created April 9, 2014 19:04
Show Gist options
  • Save kpmy/10303759 to your computer and use it in GitHub Desktop.
Save kpmy/10303759 to your computer and use it in GitHub Desktop.
PROCEDURE IntToString* (x: LONGINT; OUT s: ARRAY OF CHAR);
VAR j, k: INTEGER; ch: CHAR; a: ARRAY 32 OF CHAR;
BEGIN
IF x # MIN(LONGINT) THEN
IF x < 0 THEN s[0] := "-"; k := 1; x := -x ELSE k := 0 END;
j := 0; REPEAT a[j] := CHR(x MOD 10 + ORD("0")); x := x DIV 10; INC(j) UNTIL x = 0
ELSE
a := minLongIntRev; s[0] := "-"; k := 1;
j := 0; WHILE a[j] # 0X DO INC(j) END
END;
ASSERT(k + j < LEN(s), 23);
REPEAT DEC(j); ch := a[j]; s[k] := ch; INC(k) UNTIL j = 0;
s[k] := 0X
END IntToString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment