Created
February 23, 2015 00:21
-
-
Save poizan42/ed1de90aa63ac4352aff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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