函数搜集

//将正数字符串转化为相应的正数

float GetNum(const char *nptr)
{
 int c;              /* current char */
    long inttotal;         /* current total */
 float fractotal;
 inttotal = 0;
 /* skip whitespace */
 while ( isspace((int)(unsigned char)*nptr) )
  ++nptr;
 
 c = (int)(unsigned char)*nptr++;
 while (isdigit(c))
 {//获取整数
  inttotal = 10 * inttotal + (c - '0');     /* accumulate digit */
  c = (int)(unsigned char)*nptr++;    /* get next char */
    }
 if (*nptr)
 {//获取小数
  int i;
  fractotal=0;
  c = (int)(unsigned char)*nptr++;
  for (i=1;isdigit(c);i++)
  {
   fractotal = fractotal + pow(0.1,i) * (c - '0');     /* accumulate digit */
   c = (int)(unsigned char)*nptr++;    /* get next char */
  }
  return inttotal+fractotal;
 }
 return inttotal;
}

 

 

//将十六进制数转化为十进制数

float HexToDec(const char *nptr)
{
 int c;              /* current char */
    long inttotal;         /* current total */
 float fractotal;
 inttotal = 0;
 /* skip whitespace */
 while ( isspace(*nptr) )
  ++nptr;
 
 c = *nptr;
 while (c && c!='.')
 {//获取整数
  if (c<'A')
   inttotal = 16 * inttotal + (c - '0');
  else if (c>='A' && c<'a')
   inttotal = 16 * inttotal + 10 + (c - 'A');
  else
   inttotal = 16 * inttotal + 10 + (c - 'a');
  
  c = *(++nptr);    /* get next char */
    }
 if (*nptr)
 {//获取小数
  int i;
  fractotal=0;
  c = *(++nptr);
  for (i=1;c;i++)
  {
   if (c<'A')
    fractotal = fractotal + pow(16,-i) * (c - '0');
   else if (c>='A' && c<'a')
    fractotal = fractotal + pow(16,-i) * (c - 'A');
   else
    fractotal = fractotal + pow(16,-i) * (c - 'a');
   c = *(++nptr);    /* get next char */
  }
  return inttotal+fractotal;
 }
 return inttotal;
}

 

 

//将十进制数转化为十六进制数

void F(int n)
{
    
if ( n )
     {
          F(n
/16);
         
if (n%16 < 10) printf("%d",n%16);
         
else printf("%c",(n%16)-10+'A');
     }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值