| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2407 人关注过本帖
标题:strtonum自定义一个函数进行进制转换 如 strtonum('1AA',16) 结果为426 ...
只看楼主 加入收藏
runlwx
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-10-17
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:1 
strtonum自定义一个函数进行进制转换 如 strtonum('1AA',16) 结果为426 下列函数实现有点小问题 求解!!!
自定义一个函数进行进制转换  如 strtonum('1AA',16)  结果为426   下列函数实现有点小问题 求解!!!

function strtonum(str:string;s:integer):real;
 var
 i ,j,k,dec:integer;
c,sign:char;
sum:real;
begin
 j:=strlen(pchar(str));
 sign:='*';
 sum:=0;
 for i := 1 to j do
   begin
     c:=str[i];
     if c='0' then
     k:=0
     else if c='1' then
     k:=2
      else if c='2' then
     k:=2
      else if c='3' then
     k:=3
      else if c='4' then
     k:=4
      else if c='5' then
     k:=5
      else if c='6' then
     k:=6
      else if c='7' then
     k:=7
      else if c='8' then
     k:=8
     else if c='9' then
     k:=9
      else if c='A' then
     k:=10
      else if c='B' then
     k:=11
      else if c='C' then
     k:=12
      else if c='D' then
     k:=13
      else if c='E' then
     k:=14
      else if c='F' then
     k:=15
     else
     begin
     sign:='/';
     dec:=1;
     k:=0;
     end;
     if sign='*' then
     sum:=sum*s+k
     else
     begin
     sum:=(sum+k)/dec;
     dec:=dec*haob;
 end;
  end;
strtonum:=sum;
end;
搜索更多相关主题的帖子: function 
2013-11-20 10:44
haiou327
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:22
专家分:107
注 册:2009-4-26
收藏
得分:20 
dec:=dec*haob;//这是啥
Case of

[ 本帖最后由 haiou327 于 2013-11-20 14:32 编辑 ]
2013-11-20 14:24
快速回复:strtonum自定义一个函数进行进制转换 如 strtonum('1AA',16) 结果 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017823 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved