下载此文档

32、16、8、2进制字符串转换为10进制数字.pdf


文档分类:IT计算机 | 页数:约7页 举报非法文档有奖
1/7
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/7 下载此文档
文档列表 文档介绍
321682!"#$%&'(10!")# 16 !"#$%&'10 !(")*+, #include <> #include <> #include <> #include <> #include <> #define CONVERT_ERROR 99 #define BASE 16 char HEX[BASE]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D',\ 'E','F'}; unsigned int hex2dec(char ch) { char c; if(islower(ch)) c=toupper(ch); else c=ch; for(int i=0;i<BASE;i++) { if(c==HEX[i]) return i; } return CONVERT_ERROR; } double hexchar2dec(char* str) { double dec=; unsigned int len=strlen(str); bool flag=true; http://hi./pengjun for(unsigned int i=0;i<len;i++) { if(hex2dec(str[i])==CONVERT_ERROR) { flag=false; break; } dec += hex2dec(str[i])*pow(BASE,len-1-i); } return flag==true?dec:0; } int main() { char ch[256]; cin>>ch; cout<<hexchar2dec(ch)<<endl; getchar(); return 0; } 8 !"#$%&'10 !(") #include <> #include <> #include <> #include <> #include <> #define CONVERT_ERROR 97 #define BASE 8 char OCT[BASE]={'0','1','2','3','4','5','6','7'}; unsigned int oct2dec(char ch) { if(!isdigit(ch) || ch<'0' || ch>'7') { return CONVERT_ERROR; } http://hi./pengjun for(int i=0;i<BASE;i++) { if(ch==OCT[i]) return i; } return CONVERT_ERROR; } double octchar2dec(char* str) { double dec=; unsigned int len=strlen(str); bool flag=true; for(unsigned int

32、16、8、2进制字符串转换为10进制数字 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数7
  • 收藏数0 收藏
  • 顶次数0
  • 上传人aluyuw1
  • 文件大小0 KB
  • 时间2016-04-08