Skip to content

Instantly share code, notes, and snippets.

@letoh
Created October 28, 2012 04:28
Show Gist options
  • Select an option

  • Save letoh/3967509 to your computer and use it in GitHub Desktop.

Select an option

Save letoh/3967509 to your computer and use it in GitHub Desktop.
void print_num(int n)
{
unsigned char buf[12] = {0}, *p = buf + 10;
char minus = (n < 0);
if(n < 0) n = -n;
while(n)
{
*p-- = '0' + (n % 10);
n /= 10;
}
if(!*++p) *--p = '0';
if(minus) *--p = '-';
uart_puts(p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment