float转byte
unsigned char temp[4];
unsigned short i=0;
float floatVariable=value;
unsigned char *pdata = (unsigned char *)&floatVariable;
for(i=0;i<4;i++)
{
temp[i+1] = *pdata++;//float转BYTE
}
int 转byte
char temp[4];
unsigned short m=0;
for(m=0;m<4;m++)//int转byte
{
temp[m+1]=(value>>(24-m*8));
}
byte转int
int CountReceiveData=0;
for(int j=0;j<4;j++)
{
CountReceiveData<<=8;
Temp_Value1=(buf.data()[1+j])&(0xff);
CountReceiveData|=Temp_Value1;
}
byte转float
float CurrentReceiveData=0;
void *pf;
pf = &CurrentReceiveData;
unsigned char * px;
px=(unsigned char *)buf.data();
for(int j=0;j<4;j++)
{
*((unsigned char *)pf+j)=*(px+j+1);
}