<summary>
The number is encoded in BCD.
</summary>
<param name= "Num8bitbyte" >the num8 bit byte.</param>
<returns></returns>
public static byte[] BYTEARRAYTOBCD (byte[] num8bitbyte)//8-bit ASCII
{
byte[] Num4bitbyte = new Byte[8];
Num4bitbyte = Bitconverter.getbytes (0XFFFFFFFFFFFFFFFF);
for (int i = 0; i<num8bitbyte.length; i++)
{
byte num =convert.tobyte (Num8bitbyte[i]-0x30);
if (i% 2 = 0)
{
NUM4BITBYTE[I/2] = Convert.tobyte ((NUM4BITBYTE[I/2] & 0xF0) | num);
}
Else
{
NUM4BITBYTE[I/2] = Convert.tobyte ((NUM4BITBYTE[I/2) &0x0f) | (Num << 4));
}
}
return num4bitbyte;
}
<summary>
BCDs to String.
</summary>
<param name= "Bcdnum" >the BCD num.</param>
<returns></returns>
public static string bcdtostring (byte[] bcdnum)
{
String Retstring= "";
byte[] Bytechar = new Byte[bcdnum.length];
Bytechar = Bitconverter.getbytes (0XFFFFFFFFFFFFFFFF);
BYTE temphigh=0,templow=0;
int i = 0;
while (Temphigh!= 0x0f && templow!= 0xF0)
{
Temphigh = Convert.tobyte (Bcdnum[i] & 0xF0);//remove high four bits;
Temphigh = Convert.tobyte (Temphigh >> 4);
Templow = Convert.tobyte (Bcdnum[i] & 0x0f) << 4);
Bytechar[i] = convert.tobyte (Templow | temphigh);
i++;
}
String[] Hexstring=bitconverter.tostring (Bytechar). Trim (). Split ('-');
foreach (String str in hexstring)
{
retstring = str. Trim ();
}
int lastindex = Retstring.indexof (' F ');
return retstring = retstring.substring (0, lastindex);
}