欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C++實(shí)現(xiàn)十六進(jìn)制字符串轉(zhuǎn)換為十進(jìn)制整數(shù)的方法

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

本文實(shí)例講述了C++實(shí)現(xiàn)十六進(jìn)制字符串轉(zhuǎn)換為十進(jìn)制整數(shù)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

/*
* 將十六進(jìn)制數(shù)字組成的字符串(包含可選的前綴0x或0X)轉(zhuǎn)換為與之等價(jià)的整型值
*/
#include <stdio.h>
#include <math.h>
/* 將十六進(jìn)制中的字符裝換為對應(yīng)的整數(shù) */
int hexchtoi(char hexch )
{
 char phexch[] = "ABCDEF";
 char qhexch[] = "abcdef";
 int i;
 for(i=0;i<6;i++){
  if((hexch == phexch[i]) || (hexch == qhexch[i]))
   break;
 }
 printf("i=%d",i);
 if(i >= 6){
  return 0; /* 非十六進(jìn)制字符 */
 }
 return 10+i;
}
int htoi(char s[])
{
 int n=0; /*有n位*/
 int valu=1; /*是否有效*/
 int i=0,j;
 int answer=0;
 /* 有效性檢查 */
 if((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))){
  i += 2;
 }
 while((s[i] != '\n')){
  if((s[i] < '0') && (s[i] > '9')){
   if(hexchtoi(s[i]) == 0){
    valu=0;
    break;
   }
  }
  n++;
  i++;
 }
 if(valu != 0){   
  for(j=0;j<n;j++){
   answer += ((int)pow(16,j) * hexchtoi(s[i-j-1]));
  } 
 }
 else
  answer = -1;
 return answer;
}
main()
{
 char *n[] = {"0x7ff0","0x2341"};
 printf("%s is %d\n",n[0],htoi(n[0]));
 printf("%s is %d\n",n[0],123);
}

希望本文所述對大家的C++程序設(shè)計(jì)有所幫助。

上一篇:VC++ 獲取系統(tǒng)時(shí)間的方法匯總

欄    目:C語言

下一篇:C++隊(duì)列用法實(shí)例

本文標(biāo)題:C++實(shí)現(xiàn)十六進(jìn)制字符串轉(zhuǎn)換為十進(jìn)制整數(shù)的方法

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/2978.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有