求高手帮我分析几个函数
时间:10-02
整理:3721RD
点击:
不知道具体什么作用
void hex_2_asc(uchar *_src,unsigned int cnt,uchar *_dest)
{
while (cnt-->0)
{
if (((_src[cnt] & 0xF0)>>4)<=9) _dest[cnt*2] = 0x30 + ((_src[cnt] & 0xF0)>>4); else _dest[cnt*2] = 0x37 + ((_src[cnt] & 0xF0)>>4);
if ((_src[cnt] & 0x0F)<=9) _dest[cnt*2+1] = 0x30 + (_src[cnt] & 0x0F); else _dest[cnt*2+1] = 0x37 + (_src[cnt] & 0x0F);
}
}
void hex_2_dec(unsigned long int _hex,char *_dec)
{
unsigned char i,x;
unsigned long int J;
memset(_dec,0x00,16);
J=10000000;
for (i=0;i<8;i++)
{
x=_hex/J;
_hex=_hex-J*x;
J=J/10;
if (i % 2)
{_dec[i/2]=_dec[i/2]*16+x;}
else
{
_dec[i/2]=_dec[i/2]+x;
}
}
}
void dec_2_hex(uchar *strDec,int n,uchar *strHex)
{
int i;
unsigned long int *a;
(uchar*)a=&strHex[0];
*a=10;
for (i=0;i<n;i++)
{
(*a)=(*a)*10+strDec[i]-0x30;
}
}
void CRC16(unsigned char* src, unsigned char* crc16, int len)
{
unsigned long int crc=0;
unsigned char i;
unsigned char *ptr=src;
while (len--)
{
for (i=0x80; i!=0; i=i>>1)
{
if ((crc & 0x8000) !=0)
{
crc = crc <<1;
crc = crc^0x1021;
}
else
{
crc = crc << 1;
}
if ((*ptr & i) != 0)
{
crc = crc^0x1021;
}
}
ptr++;
}
memcpy(crc16,&crc,4);
}
void hex_2_asc 把HEX码转换成ASC码
void hex_2_dec 16进制数转换成一个十进制数
void dec_2_hex 10进制数转换成一个16进制数
void CRC16 CRC检验
我看也是,有点复杂,在研究研究,谢谢