基于LINUX操作系统下的各种详细配置(如FTP
源代码在线查看: vc中的进制转换.txt
一些进制转换的问题代码:
#include
#include
#include
#include
using namespace std;
void convert();
void main()
{
convert();
}
void convert()
{
char a[100];
int num,sum=0;
int len;
cout gets(a);
cout puts(a);
len=strlen(a);
for (int i=0;i {
{
num=(a[i]-48);
num=num*pow(2,len-i-1);
sum+=num;
}
}
cout }
//十六进制转换为二进制
CString DecimalToBinary(CString strDecimal)
{
int nDecimal = atoi(strDecimal.GetBuffer(0));
int nYushu;
int nShang;
CString strBinary = "";
char buff[2];
CString str = "";
BOOL bContinue = TRUE;
while(bContinue)
{
nYushu = nDecimal%2;
nShang = nDecimal/2;
sprintf(buff,"%d",nYushu);
str = strBinary;
strBinary.Format("%s%s",buff,str);
nDecimal = nShang;
if(nShang==0)
bContinue = FALSE;
}
return strBinary;
}
example:
CString str("5a");
CString strTemp, strRes="";
int dwValue = strtoul(str, NULL, 16);
strTemp.Format("%d", dwValue);
strRes = DecimalToBinary(strTemp);
//十进制转换为16进制
如果想把一个10进制的数字转为 16 进制的串
char buf[100];
sprintf (buf,"%X",int10);
//十六进制转换为十进制
char *p="fe";
char *str;
int i = (int)strtol(p, &str, 16);