/ Published in: C
                    
                                        
How to convert an integer from base 10 to a string of base x (where x 
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
char* convertFromDecimal(int num, int toBase) {
char chars[] = { "0123456789ABCDEFGHIJ" };
char *result;
char digit[] = { '\0', '\0' };
char temp[RESERVE_CHARS];
int over;
while (num > 0) {
over = num % toBase;
digit[0] = chars[over];
num /= toBase;
}
/* reverse the temp string to get real digit */
int p, x;
result[x] = temp[p];
}
return result;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                