如何实现文本转16进制的方法? char szHex[] = "0X0000FFFF";如何转成DWORD dwHex == 0X0000FFFF; ???给出代码,立即给分。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DWORD StrToInt2(CString str){ if( str.GetLength() <= 2 ) return 0 ; str.MakeUpper() ; if( "0X" != str.Left(2) ) return 0 ; str.Delete(0,2) ; int sum = 0 ; int index = 0 ; while( index != str.GetLength() && '0'==str[index]) index ++ ; while( index != str.GetLength() ) { char ch = str[index++] ; if( ch>= '0' && ch<='9' ) { sum = sum * 16 + ch-'0' ; continue ; } if( ch>='A' && ch<='F' ) { sum = sum * 16 + ch-'A'+10 ; continue ; } } return sum ; } 查MSDN ,可以查到 StrToIntint StrToInt( LPCTSTR lpSrc );#define StrToLong StrToInt还有 StrToIntExBOOL StrToIntEx( LPCTSTR pszString, DWORD dwFlags, int FAR * piRet ); 引入头文件 #include "SHLWAPI.H"(在 C:\Program Files\Microsoft Visual Studio\VC98\Include 中)引入库 SHLWAPI.LIB (在 C:\Program Files\Microsoft Visual Studio\VC98\Lib 中 )然后调用 StrToIntEx这样就可以了 int value ; StrToIntEx(szHex,STIF_SUPPORT_HEX,&value) ; DWORD dwHex=0;char szHex[] = "0X0000FFFF";sscanf(szHex,"0X%08X",&dwHex); int sum = 0 ;?不是DWORD嘛!^_^ 在 MSDN上查到 StrToInt 和 StrToIntEx ,但是不知道怎么才能用。抢分心切,自己写了一个 StrToInt2,嘿嘿,*^_^*自己写的肯定没有库里面的好,大家不要笑话俺。 同意DentistryDoctor(牙科医生)!^_^ DentistryDoctor(牙科医生) : 厉害哦 。 sprintf();函数也有同样的效果,还可以用IntToHex函数直接转 实时的视频采集 关于字体的缩放! 使用CArchive类应包含那个头文件? 有什么办法可以迅速得到网络地址是否可以访问 关于COM的一点问题 一边解密视频一边播放的问题! COM组件中如何添加一个Dialog呢?我一添加编译就报错! 请问一个问题,开发工具是vb好还是c++好呢,c,c++,vc之间有什么异同呢? 关于::标识符的问题 hook还是不懂,再问一回?? 如何读取特定格式的文本文件? 十万火急请问什么是3s?
{
if( str.GetLength() <= 2 )
return 0 ; str.MakeUpper() ;
if( "0X" != str.Left(2) )
return 0 ; str.Delete(0,2) ; int sum = 0 ;
int index = 0 ;
while( index != str.GetLength() && '0'==str[index])
index ++ ; while( index != str.GetLength() )
{
char ch = str[index++] ;
if( ch>= '0' && ch<='9' )
{
sum = sum * 16 + ch-'0' ;
continue ;
}
if( ch>='A' && ch<='F' )
{
sum = sum * 16 + ch-'A'+10 ;
continue ;
}
}
return sum ;
}
int StrToInt(
LPCTSTR lpSrc
);#define StrToLong StrToInt还有 StrToIntExBOOL StrToIntEx(
LPCTSTR pszString,
DWORD dwFlags,
int FAR * piRet
);
引入库 SHLWAPI.LIB (在 C:\Program Files\Microsoft Visual Studio\VC98\Lib 中 )
然后调用 StrToIntEx这样就可以了
int value ;
StrToIntEx(szHex,STIF_SUPPORT_HEX,&value) ;
char szHex[] = "0X0000FFFF";
sscanf(szHex,"0X%08X",&dwHex);
不是DWORD嘛!^_^
^_^