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

Newbie = Extracting Bits

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



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

Newbie = Extracting Bits
PostPosted: Fri Dec 08, 2006 11:45 pm     Reply with quote

How do I go about extract bits from a int16
Example
int16 Msg

MyID is the first 3 bits on the left
FirstVal is the next 5 bits
2nd val is the next 4 bits
3rd val is the next 4 bits

and so on ....

Could I define a struct with the proper bits like this

struct myrec {
int8 myid :3;
int8 firstval :5;
int8 secval : 4;
int8 thirdval : 4;
};

myrec = mymsg;

Will that load the proper fileds with the proper bits?
If not how is the best way to do it?

THX
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

Fixed
PostPosted: Sat Dec 09, 2006 2:19 am     Reply with quote

Nevermind, I wrote a function that took the starting bit and the number of bits and shifted them till I got what I needed.
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