浏览 719 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2016-09-06
在Linux GCC编译测试通过,代码如下: ~~~.c #include <stdio.h> void tobase(int, int); int main() { tobase(33, 16); return 0; } void tobase(int value, int base) { static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char buf[(sizeof(long) << 3) + 1]; char *ptr, *end; if (base < 2 || base > 36) { printf("error base range \n"); } end = ptr = buf + sizeof(buf) - 1; *ptr = '\0'; do { *--ptr = digits[value % base]; value /= base; } while (ptr > buf && value); printf("base: %d, => %s \n", base, ptr); } ~~~ 转自:http://www.yinqisen.cn/blog-673.html 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |