大家来帮忙:面试问题 将下面的十六进制的BCD码转换为真正的十进制数: 十六进制:12 34 56 78(分别在四个八位的字节中存放) 转换:12345678 (要求在一个DWORD型变量中存放) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 union myint{ BYTE a1[4]; int b;};union mydword{ int b1; DWORD c;};CString CDialogDlg::ConvertASC2(BYTE a, BYTE b){ myint myunion; CString str; BYTE high, low, data[4]; myunion.a1[0]=myunion.a1[1]=myunion.a1[2]=myunion.a1[3]=0x00; myunion.a1[0]=a; high=myunion.a1[0]&0xF0; high=high>>4; high=high&0x0F; data[0]=high; low=myunion.a1[0]&0x0F; data[1]=low; myunion.a1[0]=b; high=myunion.a1[0]&0xF0; high=high>>4; high=high&0x0F; data[2]=high; low=myunion.a1[0]&0x0F; data[3]=low; str.Format("%d%d%d%d", data[0], data[1], data[2], data[3]); return str;}BYTE a[4]; // to load BCDmydword test; // to load ASC2CString str, str1, str2;DWORD result;a[0]=0x12;a[1]=0x34;a[2]=0x56;a[3]=0x78;str1=ConvertASC2(a[0], a[1]);str2=ConvertASC2(a[2], a[3]);str=str1+str2;test.b1=atoi(str);result=test.c;result应该是你要的结果!!!不知道对不对,你看看吧!!! 上面的方法太累了,这个方法好像也可以呀!!!union mydword{ int b1; DWORD c;};BYTE a[4]; // to load BCDCString str;mydword test;DWORD result;a[0]=0x12;a[1]=0x34;a[2]=0x56;a[3]=0x78;str.Format("%x%x%x%x", a[0], a[1], a[2], a[3]);test.b1=atoi(str);result=test.c; #define HEXASCII(val) ((val)>0 && (val)<10)?'0'+(val):\ ((val)>9 && (val)<16)?'A'+(val)-10:\ '0'void CCharDlg::OnButton1() { // TODO: Add your control notification handler code here char buf[]={0x12,0x34,0x56,0x78,'\0'}; CString temp=buf; CString temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8; //HEXASCII temp1=HEXASCII((temp[0]&0xf0)>>4); temp2=HEXASCII(temp[0]&0x0f); temp3=HEXASCII((temp[1]&0xf0)>>4); temp4=HEXASCII(temp[1]&0x0f); temp5=HEXASCII((temp[2]&0xf0)>>4); temp6=HEXASCII(temp[2]&0x0f); temp7=HEXASCII((temp[3]&0xf0)>>4); temp8=HEXASCII(temp[3]&0x0f); CString result1=(temp1+temp2+temp3+temp4+temp5+temp6+temp7+temp8); //再把result1转化成DWORD型的........} 如果没有CString怎么办,也可以向下面这样:union mydword{ int b1; DWORD c;};BYTE a[4]; // to load BCDchar str[4];mydword test;DWORD result;a[0]=0x12;a[1]=0x34;a[2]=0x56;a[3]=0x78;memset(str, 0, 4);sprintf(str, "%x%x%x%x", a[0], a[1], a[2], a[3]);test.b1=atoi(str);result=test.c; 请问如何把内存映射文件的内容保存为硬盘文件? 字符串问题 在线等!!!!!!! 怎样现实sort arrow 有没有办法显示一个灰度级别大于256的图。 什么情况下才要把lib文件加到我当前的工程当中? 小问题! 表中记录的删除?? 有关通过COM在进程间传递HWND参数的问题,急!急!急! MFC应用程序, 支持ActiveX就等于支持Automation吗? Winsock2 SPI截获不到IE的http 菜鸟级问题,请求帮助 为什么在CWinThread::InitInstance里使用CDaoDatabase::Execute()就会报错
{
BYTE a1[4];
int b;
};union mydword
{
int b1;
DWORD c;
};CString CDialogDlg::ConvertASC2(BYTE a, BYTE b)
{
myint myunion;
CString str;
BYTE high, low, data[4];
myunion.a1[0]=myunion.a1[1]=myunion.a1[2]=myunion.a1[3]=0x00;
myunion.a1[0]=a;
high=myunion.a1[0]&0xF0;
high=high>>4;
high=high&0x0F;
data[0]=high;
low=myunion.a1[0]&0x0F;
data[1]=low;
myunion.a1[0]=b;
high=myunion.a1[0]&0xF0;
high=high>>4;
high=high&0x0F;
data[2]=high;
low=myunion.a1[0]&0x0F;
data[3]=low;
str.Format("%d%d%d%d", data[0], data[1], data[2], data[3]);
return str;
}BYTE a[4]; // to load BCD
mydword test; // to load ASC2
CString str, str1, str2;
DWORD result;
a[0]=0x12;
a[1]=0x34;
a[2]=0x56;
a[3]=0x78;
str1=ConvertASC2(a[0], a[1]);
str2=ConvertASC2(a[2], a[3]);
str=str1+str2;
test.b1=atoi(str);
result=test.c;
result应该是你要的结果!!!
不知道对不对,你看看吧!!!
union mydword
{
int b1;
DWORD c;
};BYTE a[4]; // to load BCD
CString str;
mydword test;
DWORD result;
a[0]=0x12;
a[1]=0x34;
a[2]=0x56;
a[3]=0x78;
str.Format("%x%x%x%x", a[0], a[1], a[2], a[3]);
test.b1=atoi(str);
result=test.c;
((val)>9 && (val)<16)?'A'+(val)-10:\
'0'
void CCharDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char buf[]={0x12,0x34,0x56,0x78,'\0'};
CString temp=buf;
CString temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8;
//HEXASCII
temp1=HEXASCII((temp[0]&0xf0)>>4);
temp2=HEXASCII(temp[0]&0x0f);
temp3=HEXASCII((temp[1]&0xf0)>>4);
temp4=HEXASCII(temp[1]&0x0f);
temp5=HEXASCII((temp[2]&0xf0)>>4);
temp6=HEXASCII(temp[2]&0x0f);
temp7=HEXASCII((temp[3]&0xf0)>>4);
temp8=HEXASCII(temp[3]&0x0f);
CString result1=(temp1+temp2+temp3+temp4+temp5+temp6+temp7+temp8);
//再把result1转化成DWORD型的........
}
union mydword
{
int b1;
DWORD c;
};BYTE a[4]; // to load BCD
char str[4];
mydword test;
DWORD result;a[0]=0x12;
a[1]=0x34;
a[2]=0x56;
a[3]=0x78;
memset(str, 0, 4);
sprintf(str, "%x%x%x%x", a[0], a[1], a[2], a[3]);
test.b1=atoi(str);
result=test.c;