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

32bit struct

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



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

32bit struct
PostPosted: Fri May 28, 2004 7:52 am     Reply with quote

Today I figured out that I can't create a 32bit structure like this:

Code:
   
   struct reg_timestamp
   {
      int day;      : 5;      // dia (1 - 31)
      int month;      : 4;      // mes (1 - 12)
      int year;      : 6;      // ano (0 - 64), simbolizando 2000 a 2064
      int hour;      : 5;      // hora (0 - 23)
      int minu      : 6;      // minutos (0 - 59)
      int seco      : 6;      // segundos (0 - 59)
   } int32 timestamp;   

Is that right?

Is the only way to create a 32bit variable and rotate each bit to inside the variable?

Thanks,

Marcus
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri May 28, 2004 8:20 am     Reply with quote

You should be able to get the structure working but it should comile like this does.

Int32 timestamp;

int8 day;
int8 Month;
int8 Year;
int8 Hour;
int8 Min;
int8 Sec;

timestamp=sec;
timestamp+=((int16)Min<<6);
timestamp+=((int32)Hour<<12);
timestamp+=((int32)Year<<17);
timestamp+=((int32)Month<<23);
timestamp+=((int32)day<<27);


Using a structure throughout your program is not going to generate efficient code. Do the conversion to and from the compressed format before and after storage. This is going to run much faster and use less ROM at the cost of a few waisted bytes of RAM.
mvaraujo



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

PostPosted: Fri May 28, 2004 8:23 am     Reply with quote

Neutone,

Great, simply definitive!

Thanks,

Marcus
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