//Prj: 0600 gps+compass
U32 power(int base, int times)
{
int i;
U32 rslt = 1;
for (i=0;i<times;i++)
{
rslt *= base;
}
return rslt;
}
U32 BCD2Dec(U8 *pBcd, int len)
{
int i, temp;
U32 dec=0;
for (i=0; i<len; i++)
{
temp = ( (pBcd[i]>>4)&0x0f)*10 + (pBcd[i]&0x0f);
dec += temp * power(100, len-1-i) ;
//dbg0printf("%02X, temp:%d, dec:%d\r\n", pBcd[i], temp, dec);
}
return dec;
}
void Dec2BCD(int dec, U8* pBcd, U8 len)
{
int i;
int temp;
for (i=len-1; i>=0; i--)
{
temp = dec%100;
pBcd[i] = ( (temp/10)<<4) + ( (temp%10&0x0f) );
dec/=100;
}
}
13.01.24 转换 BCD码
最新推荐文章于 2021-07-27 13:36:30 发布