This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Explanation

Hello

Below are the functions to convert a 3 digit decimal to BCD format and to convert from 3 digit BCD to Binary. Can anyone please explain it clearly??


/************************************************************************/
/*      Name : WORDToBCD3 to Converts a 3 digit decimal to BCD format        */
*************************************************************************/

u16 WORDToBCD3(u16 value)
{
u16 bcdhigh = 0;
while (value >= 100)
{
bcdhigh++;
value -= 100;
}
bcdhigh <<= 4;
while (value >= 10)
{
bcdhigh++;
value -= 10;
}
return (bcdhigh << 4) | value;
}
/************************************************************************/
/*      Name : BCD3ToWORD to convert from 3 digit BCD to Binary        */
*************************************************************************/
u16 BCD3ToWORD(u16 value)
{
return (u16)((((value&0xF00)>>8)*100) + (((value&0x0F0)>>4)*10) +
(value&0x0F));
}

Parents Reply Children
No data