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 CCS Technical Support

int to decade out

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








int to decade out
PostPosted: Tue Mar 27, 2007 6:53 am     Reply with quote

This isn't really a PIC issue, but a C programming question. How can I break an int into 12 decade bits? It's not so easy as a normal binary conversion. Also, the less time it takes to convert the number, the better.

Example, if I had an int with value 234, I would want to break this into 0010 0011 0100 and output each bit on a seperate pin. These will be used for 3 seven-segment displays.
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Tue Mar 27, 2007 7:16 am     Reply with quote

This is just one way to do it.


Code:

   unsigned int8 i = 234;
   unsigned int8 huns, tens, ones;


   huns = i / 100;
   tens = ( i - ( huns * 100 ) ) / 10;
   ones = i - ( ( huns * 100 ) + ( tens * 10 ) );
Ttelmah
Guest







PostPosted: Tue Mar 27, 2007 8:17 am     Reply with quote

A search for 'BCD' (binary coded decimal - what this format is called), will find several conversion routines, including some very efficient ones.

Best Wishes
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