Skip to content

Instantly share code, notes, and snippets.

@poizan42
Created February 23, 2015 00:21
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 poizan42/ed1de90aa63ac4352aff to your computer and use it in GitHub Desktop.
Save poizan42/ed1de90aa63ac4352aff to your computer and use it in GitHub Desktop.
void write_int(int n) {
// Length of INT_MIN as a decimal number is 11 (-2147483647)
char buf[11];
int neg = n < 0;
n *= 1 - 2*neg;
int pos = 11;
do {
buf[--pos] = '0' + (n % 10);
n /= 10;
} while (n);
if (neg) {
buf[--pos] = '-';
}
syscall_write(1, &buf[pos], 11-pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment