CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

BCD to byte and back

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
picker



Joined: 07 Sep 2003
Posts: 19
Location: South Africa

View user's profile Send private message

BCD to byte and back
PostPosted: Mon Jan 05, 2004 2:34 am     Reply with 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?

Thanks
Kevin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 05, 2004 2:54 am     Reply with quote

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
PostPosted: Mon Jan 05, 2004 5:21 am     Reply with quote

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

View user's profile Send private message

BCD to Byte and back
PostPosted: Mon Jan 05, 2004 6:06 am     Reply with quote

Thanks guys...
KerryW
Guest







BCD math
PostPosted: Mon Jan 05, 2004 9:03 am     Reply with quote

int8 BCDval

if ((++BCDval & 0xF)==0xA) BCDval+=5;

Shouldn't that be
if ((++BCDval & 0xF)==0xA) BCDval+=6; ?
Ttelmah
Guest







Re: BCD math
PostPosted: Mon Jan 05, 2004 4:38 pm     Reply with quote

KerryW wrote:
int8 BCDval

if ((++BCDval & 0xF)==0xA) BCDval+=5;

Shouldn't that be
if ((++BCDval & 0xF)==0xA) BCDval+=6; ?

Yes...
Sorry, a 'mistype'.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group