严重声明一下,这个算法不是本人搞得,其实就是HextoBCD,只是我觉得算法挺不错,匠人看到没?是不是觉得很熟悉阿?这个来自于你的匠人手记里介绍的算法.比较不错,能节省很多资源.哈哈哈
unsigned long HexToBCD(unsigned int uiData)
{
unsigned long uiBuf = 0;
unsigned int ucCount = 0;
for(ucCount = 0;ucCount < 15;ucCount ++)
{
if (uiData & 0x8000) uiBuf |= 0x01;
uiData <<= 1;
if((uiBuf + 0x03)&0x0008)
uiBuf += 3;
if((uiBuf + 0x30)&0x0080)
uiBuf += 0x30;
if((uiBuf + 0x300)&0x0800)
uiBuf += 0x300;
if((uiBuf + 0x3000)&0x8000)
uiBuf += 0x3000;
if((uiBuf + 0x30000)&0x80000)
uiBuf += 0x30000;
uiBuf <<= 1;
}
if (uiData & 0x8000) uiBuf |= 0x01;
return uiBuf;
} |