CSDN博客

img maisuiki

十进制与十六进制转换(面试题)

发表于2008/9/29 11:29:00  753人阅读

分类: it

面试的时候遇到这道题,居然做不对,有点郁闷

 

1、十六进制转十进制
long HexToDem(unsigned long HexNum)
{
  long DemNum=0;
  char string[8];
  sprintf(string,"%ld",HexNum);
  DemNum=atol(string);
  return DemNum;
}
2、十进制字符串转十六进制
CString DecToHex(CString strDec)
{
double dblData = 0;
char chsData[128];
CString strHec;
sscanf(strDec.GetBuffer(strDec.GetLength()),"%f",&dblData);
strHec.Format("%x", dblData);

return strHec;
}
3、十进制转十六进制
CString CSegInfo::algorismtohex(int algorism)//十六进制转换
{
CString str;
switch(algorism)
{
case 10:
str="A";
break;
case 11:
str="B";
break;
case 12:
str="C";
break;
case 13:
str="D";
break;
case 14:
str="E";
break;
case 15:
str="F";
break;
default:
str.Format("%d",algorism);
}
return str;
}
void mydialog::OnButton()
{UpdateData();
m_edit2=algorismtohex(m_edit1);]
UpdateData(FALSE);
}
edit1 int型
edit2 CString型

阅读全文
0 0

相关文章推荐

img
取 消
img