-
-
[原创分享]VC++进制转换程序
-
发表于:
2010-2-21 01:10
6228
-
/*****************************************************************************
file name : data_exchange.h
author : succeswing
date : 2010.1.1
description : the profil is BinaryConversion
Noticed : should be complied with VC6.0
version : 1.0
E-mail : succeswing#gmail.com(the # is @)
******************************************************************************/
#include <string>
#include <cmath>
#include <stdlib.h>
CString BinToDec(CString strbin)
{
int len;
int i;
long dec;
CString strdec;
dec=0;
len=strbin.GetLength();
for(i=0;i<len;i++)
{
if(strbin[len-i-1]!='0')
{
dec=dec+pow(2,i);
}
}
strdec.Format("%d",dec);
return strdec;
}
CString DecToBin(CString strdec)
{
int dec;
CString strbin;
dec=atoi(strdec);
while(dec!=0)
{
if(dec%2)
{
dec=dec/2;
strbin.Insert(0,"1");
}
else
{
dec=dec/2;
strbin.Insert(0,"0");
}
}
strbin.Insert(0,"0");
return strbin;
}
CString DecToHex(CString strdec)
{CString strhex;
int dec;
dec=atoi(strdec);
strhex.Format("%x",dec);
return strhex;
}
CString HexToDec(CString strhex)
{CString strdec;
DWORD hex;
hex=strtoul(strhex, NULL, 16);
strdec.Format("%d",hex);
return strdec;
}
CString BinToHex(CString strbin)
{ CString strhex;
strhex=DecToHex(BinToDec(strbin));
return strhex;
}
CString HexToBin(CString strhex)
{
CString strbin;
strbin=DecToBin(HexToDec(strhex));
return strbin;
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课