System.out.println();
String s = new String(pbyOutBuffer);
System.out.printf("%d,%s\n" ,s.length(),s);
for(int i=0;i<s.length();i++)
System.out.printf("%02X ", (int)s.toCharArray()[i] );
}
public static int EncPack(char[] pbyInBuffer, char[] pbyOutBuffer, int iInBuffLen)
{
char n;
int iLen, i;
/*
* * whether InBuffer data's len can be divided by 2
*/
if (iInBuffLen % 2 > 0)
iLen = iInBuffLen + 1;
else
iLen = iInBuffLen;
for (i = 0; i < iInBuffLen; i++)
{
pbyInBuffer[i] = Character.toUpperCase(pbyInBuffer[i]);
if (i % 2 != 0) /* if odd number */
{
n = (char) ((char)pbyInBuffer[i] - 0x30);
/*
* * Note: 'A' = 65, 'F'= 70. 65-48 = 17, 17-7=10. *
* For example, this will convert 'A' to value 10.
*/
if (n > 9)
n = (char)(n - 7);
pbyOutBuffer[i / 2] = (char)(pbyOutBuffer[i / 2] | n);
} else
{
//pbyOutBuffer[i / 2] = ((n = pbyInBuffer[i] - 0x30) > 9 ? n - 7 : n) << 4 ;
n = (char)(pbyInBuffer[i] - 0x30);
if( n > 9 ) n = (char)(n - 7);
pbyOutBuffer[i / 2] = (char)(n << 4);
}
}
return (iLen / 2);
}
}