您的位置:首页 > 其它

汉子转化为十六进制和二进制

2014-04-26 10:19 253 查看


以上是界面

下面是主要代码:

void CHz_to_UnicodeDlg::OnBnTranslate()

{

 // TODO: 在此添加控件通知处理程序代码

 

 UpdateData(true);

 m_tensting = L"";

 m_binary = L"";

 m_sixTeen = L"";

 CString PP;

 PP=m_sting;

 if(m_sting.IsEmpty())

 {

  AfxMessageBox(L"请输入汉字!");

  return;

 }

 int len=PP.GetLength();

 int unicode;                     //十进制转化为十六进制进用到的中间值

 const int MAX_FILE_LENGTH=500;

 WCHAR UnicodeFile[MAX_FILE_LENGTH];

 char ch[32];

 memset(UnicodeFile,0,sizeof(UnicodeFile));

 memset(ch,0,sizeof(ch));

 WideCharToMultiByte(CP_OEMCP, NULL,PP, -1, ch, sizeof(ch)-1, NULL, FALSE);

 MultiByteToWideChar( CP_ACP, 0,ch,-1,UnicodeFile,MAX_FILE_LENGTH);

 PP="";

 CString midd,temp=L"",two = L"";//中间值

 for(int loop=0;loop<len;loop++)

 {

  unicode=UnicodeFile[loop];

  //m_binary=tentobinary(unicode);

  _itoa(unicode,ch,2);

  temp = ch;

  m_binary = m_binary + temp;

  midd.Format(L"%d",unicode);

  temp.Format(L"%d",unicode);

  m_tensting =m_tensting+temp;

  m_tensting =m_tensting+L" ";

  _itoa(unicode,ch,16);

  temp = ch;

  m_sixTeen = m_sixTeen + temp;

 }

 UpdateData(false);

}

完整工程放在资源里(Hz_To_Unicode)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息