Joined: 07 Sep 2003 Posts: 19 Location: South Africa
BCD to byte and back
Posted: Mon Jan 05, 2004 2:34 am
I need to increment a BCD value. My thoughts were to convert the BCD to a byte add 1 and then convert back to BCD. Does anyone have any code that converts BCD to Byte and back?
Thanks
Kevin
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Jan 05, 2004 2:54 am
Quote:
I need to increment a BCD value. My thoughts were to convert
the BCD to a byte add 1 and then convert back to BCD. Does
anyone have any code that converts BCD to Byte and back?
I think you could write code to do it without converting back
and forth to binary, but to answer your question:
There is code in the archives to do this. Do a search for bin2bcd
and you'll find that routine and its mate, bcd2bin.
Ttelmah Guest
Re: BCD to byte and back
Posted: Mon Jan 05, 2004 5:21 am
picker wrote:
I need to increment a BCD value. My thoughts were to convert the BCD to a byte add 1 and then convert back to BCD. Does anyone have any code that converts BCD to Byte and back?
Thanks
Kevin
More work than is needed. :-)
int8 BCDval
if ((++BCDval & 0xF)==0xA) BCDval+=5;
A lot less work than performing the two conversions.
Best Wishes
picker
Joined: 07 Sep 2003 Posts: 19 Location: South Africa
BCD to Byte and back
Posted: Mon Jan 05, 2004 6:06 am
Thanks guys...
KerryW Guest
BCD math
Posted: Mon Jan 05, 2004 9:03 am
int8 BCDval
if ((++BCDval & 0xF)==0xA) BCDval+=5;
Shouldn't that be
if ((++BCDval & 0xF)==0xA) BCDval+=6; ?
Ttelmah Guest
Re: BCD math
Posted: Mon Jan 05, 2004 4:38 pm
KerryW wrote:
int8 BCDval
if ((++BCDval & 0xF)==0xA) BCDval+=5;
Shouldn't that be
if ((++BCDval & 0xF)==0xA) BCDval+=6; ?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum