十进制转16进制 、十进制转二进制 函数
include "string.h"
include "stdio.h"
char *dectohex(int dec, int len)
{
static char buf[256];
char cell[] = "0123456789ABCDEF";
int i = 0;
memset(buf, 0, 256);
memset(buf, '0', len);
while (dec != 0)
{
buf[i++] = cell[dec % 16];
dec = dec / 16;
}
strcat(buf, "x0");
return (strrev(buf));
}
char *dectobin(int dec, int len)
{
int i = 0;
static char buf[256];
memset(buf, 0, 256);
memset(buf, '0', len);
while (dec != 0)
{
buf[i++] = dec % 2+48;
dec = dec / 2;
}
return strrev(buf);
}
专注于企业信息化,最近对股票数据分析较为感兴趣,可免费分享股票个股主力资金实时变化趋势分析工具,股票交流QQ群:457394862
分类: C/C++
本文转自沧海-重庆博客园博客,原文链接:http://www.cnblogs.com/omygod/archive/2006/11/08/554685.html,如需转载请自行联系原作者