#include
#include
#define ISNULL(pszIn) pszIn==NULL
static char* AFA_DoubleByteToByte(char* pszIn,unsigned int inLen,char* pszOut,unsigned int* outLen)
{
int i;
int j;
char HIBYTE;
char LOBYTE;
if(ISNULL(pszIn)||ISNULL(pszOut)||ISNULL(outLen))
{
return (NULL);
}
if((inLen%2)!=0)
{
pszOut[0]=0;
outLen[0]=0;
}
else
{
for(i=0,j=0;i
{
HIBYTE = 0;
LOBYTE = 0;
/*
if(pszIn[i] >='a')
{
HIBYTE = (pszIn[i]-0x57);
}
*/ if(pszIn[i] >='A')
{
HIBYTE = (pszIn[i]-0x37);
}
else
{
HIBYTE = (pszIn[i]-0x30);
}
if(pszIn[i+1] >='a')
{
LOBYTE = (pszIn[i+1]-0x57);
}
else if(pszIn[i+1] >='A')
{
LOBYTE = (pszIn[i+1]-0x37);
}
else
{
LOBYTE = (pszIn[i+1]-0x30);
}
pszOut[j]=((HIBYTE << 4) & 0xF0) | (LOBYTE & 0x0F);
i++;
}
pszOut[j]=0;
outLen[0]=j;
}
return (pszOut);
}
unsigned char * AFAAPI_ByteToDoubleByte(unsigned char * pszIn,unsigned char * pszOut,int iLen)
{
int i;
unsigned char HIBYTE;
unsigned char LOBYTE;
for(i=0;i
{
HIBYTE = (unsigned char)(pszIn[i] >> 4 ) & 0x0F;
LOBYTE = (unsigned char)(pszIn[i] & 0x0F);
if(HIBYTE > 0x09)
{
pszOut[(i*2)]=HIBYTE + 0x37;
}
else
{
pszOut[(i*2)]=HIBYTE + 0x30;
}
if(LOBYTE > 0x09)
{
pszOut[(i*2+1)]=LOBYTE + 0x37;
}
else
{
pszOut[(i*2+1)]=LOBYTE + 0x30;
}
}
pszOut[(i*2)]=0;
pszOut[(i*2+1)]=0;
return (pszOut);
}
int main()
{
char sing_str[100];
char double_str[100];
char str[100];
memset(sing_str,0,100);
memset(double_str,0,100);
memset(str,0,100);
strcpy(sing_str,"abcd");
int len;
AFAAPI_ByteToDoubleByte(sing_str,double_str,4);
AFA_DoubleByteToByte(double_str,strlen(double_str),str,&len);
printf("sing_str=%s\n",sing_str);
printf("double_str=%s\n",double_str);
printf("str=%s\n",str);
printf("the len is %d\n",len);
return 0;
}
阅读(438) | 评论(0) | 转发(0) |