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

Conversion and manipulation between 8 and 16 bit variables
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah
Guest







Re: arrays?
PostPosted: Thu Nov 13, 2003 3:32 am     Reply with quote

DragonPIC wrote:
I was responding to the original post. I seen nothing of arrays. Just a word and 2 byte variables.

Anyways

Code:
int make_8_from_16(long word, short high_low)
{
#BYTE word0 = word
#BYTE word1 = word + 1

   if(high_low == 1)
      return(word1);
   else
      return(word0);
}


Maybe not the best way to approuch it, but it works. You just have to think about it.


The danger of replying to the original 'question' (which so often leaves things out), rather than the 'thread'...
If you look at the reply from the original poster, to earlier suggestions, he came back, and turned out to want an array of data that could be initialised automatically as well.
There are dozens of variants on how to do this. Your routine, uses the same basic 'trick', as my union version, and is a pretty good way to do it, and I suspect will normally be treated as 'inline', giving efficient code. :-)

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
Goto page Previous  1, 2
Page 2 of 2

 
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