10进制转换16进制,请大家帮助 将一个10进制的CString buffer= 832转换成16进制的CString temp = 340该如何转换呢? printf("%x",xx);?这样可以不?感谢~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString str = "832"; int n = atoi(str); CString str1; str1.Format("0x%x",n); AfxMessageBox(str1); CString buffer= 832;int num = atoi(buffer);temp.Format("%x",num); CString sVal = "832";int n = atoi(sVal);CString sRVal;sRVal.Format("%x",n); CString convert,strposx,strposy;; int posx,posy; BYTE Buffer[0x38] = {0}; pGenTwDlg->pDebugDlg->m_PosxEdit.GetWindowText(strposx); posx = atoi((char*)(LPCTSTR)strposx); convert.Format(_T("%x"),posx*0x40); memcpy_s(Buffer+0x10,0x02,convert,0x02); pGenTwDlg->pDebugDlg->m_PosyEdit.GetWindowText(strposy); posy = atoi((char*)(LPCTSTR)strposy); convert.Format(_T("%x"),posy*0x40); memcpy_s(Buffer+0x14,0x02,convert,0x02); memcpy_s(Buffer+0x18,0x02,convert,0x02);为什么不对不对呢,我输入一个10进制的值 32时即(0x20),获取控件值后再乘以64,然后转化为16进制但是结果总是不对,结果老是显示40... 调了半天也不知道是怎么回事如果我输入一个20时,Posx得到的值就变成02了。。不明白他是怎么弄得. convert.Format(_T("%x"),posx*0x40);加断点,看下convert 永远都是40。。pGenTwDlg->pDebugDlg->m_PosyEdit.GetWindowText(strposy);posy = atoi((char*)(LPCTSTR)strposy);获取的控制值是对的,但是转换完赋给posy就不对了 你把调试过程中,posx和convert的值贴出来。 我好想知道问题出在哪里了。posy = atoi((char*)(LPCTSTR)strposy);格式转换的时候用(char*)的时候它总是取数组的第一个值。。 如果输入20,它就取2如果输入120,它就取1这个可怎么办呢。 (char*)(LPCTSTR)可以都去掉,不过这个是问题所在吗? atoi的参数需要一个const char*,难道我还要去重新定义类型。。转换的代码看的乱乱的 不行的啦。error C2664: “atoi”: 不能将参数 1 从“CString”转换为“const char *” posx = atoi((char*)(LPCTSTR)strposx);改成posx = atoi(strposx);不需要进行复杂的转换。 额,分不是重要的。 他们助人为乐顺便得分,主要的是能帮得到我。我这个设置的字符集的问题像convert.Format(_T("%x"),posy*0x40);都需要_T宏的所以posx = atoi(strposx);这句编辑都过不去的 error C2664: “atoi”: 不能将参数 1 从“CString”转换为“const char *” char* pstr = strposx.GetBuffer(strposx.GetLength());posx = atoi(pstr );如果改成这样子又提示我字符集的问题 WTchar_T* to char * char * CDlg::w2c(wchar_t * s){ int iSize; char* pszMultiByte; iSize = WideCharToMultiByte(CP_ACP, 0, s, -1, NULL, 0, NULL, NULL); pszMultiByte = new char[iSize+1]; WideCharToMultiByte(CP_ACP, 0, s, -1, pszMultiByte, iSize, NULL, NULL); return pszMultiByte;}char* pstr = w2c(strposx.GetBuffer()); posx = atoi(pstr);这样就可以了再次感谢大家在百忙之中抽出时间来解答我的问题。 读取单个字符,用char,还是用wchar来接受? 程序太耗资源 [求助]怎样改变字体、图形变色? PdhAddCounter()使用的问题 如何处理EDIT BOX里的读取错误??? 告急:怎样访问数据库? 线程的问题,向高手请教 哪位知道如何作像金山词霸那样的Cool的弹出菜单 创建一个新的画刷这么困难吗? vs2008开发wince平台程序 VC编译出错 关于VS2008的工具栏问题
int n = atoi(str);
CString str1;
str1.Format("0x%x",n);
AfxMessageBox(str1);
int num = atoi(buffer);
temp.Format("%x",num);
int n = atoi(sVal);
CString sRVal;
sRVal.Format("%x",n);
int posx,posy;
BYTE Buffer[0x38] = {0};
pGenTwDlg->pDebugDlg->m_PosxEdit.GetWindowText(strposx);
posx = atoi((char*)(LPCTSTR)strposx);
convert.Format(_T("%x"),posx*0x40);
memcpy_s(Buffer+0x10,0x02,convert,0x02);
pGenTwDlg->pDebugDlg->m_PosyEdit.GetWindowText(strposy);
posy = atoi((char*)(LPCTSTR)strposy);
convert.Format(_T("%x"),posy*0x40);
memcpy_s(Buffer+0x14,0x02,convert,0x02);
memcpy_s(Buffer+0x18,0x02,convert,0x02);为什么不对不对呢,我输入一个10进制的值 32时即(0x20),获取控件值后再乘以64,然后转化为16进制
但是结果总是不对,结果老是显示40...
调了半天也不知道是怎么回事
如果我输入一个20时,Posx得到的值就变成02了。。不明白他是怎么弄得.
加断点,看下convert
pGenTwDlg->pDebugDlg->m_PosyEdit.GetWindowText(strposy);
posy = atoi((char*)(LPCTSTR)strposy);
获取的控制值是对的,但是转换完赋给posy就不对了
posy = atoi((char*)(LPCTSTR)strposy);
格式转换的时候用(char*)的时候它总是取数组的第一个值。。
如果输入20,它就取2
如果输入120,它就取1
这个可怎么办呢。
难道我还要去重新定义类型。。
转换的代码看的乱乱的
error C2664: “atoi”: 不能将参数 1 从“CString”转换为“const char *”
改成posx = atoi(strposx);不需要进行复杂的转换。
他们助人为乐顺便得分,主要的是能帮得到我。
我这个设置的字符集的问题
像convert.Format(_T("%x"),posy*0x40);都需要_T宏的
所以posx = atoi(strposx);这句编辑都过不去的
error C2664: “atoi”: 不能将参数 1 从“CString”转换为“const char *”
posx = atoi(pstr );
如果改成这样子又提示我字符集的问题 WTchar_T* to char *
{
int iSize;
char* pszMultiByte;
iSize = WideCharToMultiByte(CP_ACP, 0, s, -1, NULL, 0, NULL, NULL);
pszMultiByte = new char[iSize+1];
WideCharToMultiByte(CP_ACP, 0, s, -1, pszMultiByte, iSize, NULL, NULL);
return pszMultiByte;
}
char* pstr = w2c(strposx.GetBuffer());
posx = atoi(pstr);
这样就可以了
再次感谢大家在百忙之中抽出时间来解答我的问题。