Created
November 3, 2017 01:01
-
-
Save ruda/5d768604bbc0a02c866c502b4d33592a to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* From http://c-faq.com/misc/hexio.html | |
* modified for padding zeros - ruda | |
*/ | |
#define NULL 0 | |
char * | |
baseconv(unsigned int num, int base) | |
{ | |
static char retbuf[8+1]; | |
char *p; | |
if(base < 2 || base > 16) | |
return NULL; | |
p = &retbuf[sizeof(retbuf)-1]; | |
*p = '\0'; | |
do { | |
*--p = "0123456789abcdef"[num % base]; | |
num /= base; | |
} while(num != 0); | |
while (p != retbuf) | |
*--p = '0'; | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment