在发送端,uiRTUid是一个结构体的long 变量,
cSendBuffer[1] = (char)com_configpara.uiRTUid;
cSendBuffer[2] = (char)(com_configpara.uiRTUid>>8);
cSendBuffer[3] = (char)(com_configpara.uiRTUid>>16);
cSendBuffer[4] = (char)(com_configpara.uiRTUid>>24);
如何在接收端将其还原为一个整数??
cSendBuffer[1] = (char)com_configpara.uiRTUid;
cSendBuffer[2] = (char)(com_configpara.uiRTUid>>8);
cSendBuffer[3] = (char)(com_configpara.uiRTUid>>16);
cSendBuffer[4] = (char)(com_configpara.uiRTUid>>24);
如何在接收端将其还原为一个整数??
_ttoi
_atol
_ttol
可以定义long l;
l1 = buffer[1]
l2 = buffer[2]
l3 = buffer[3]
l4 = buffer[4]
l = l1 || (l2<<8) || (l3<<16) || (l4 <<24)
然后顺便移位~~~搞定嘿嘿,做个沙发
int a=ntohl(*(int*)(buffer));