Jump to content
tom 2007

Bits In Struct

Recommended Posts

tom 2007    0

Hello all,

 

Is there anyway to access bits in a variable (unsigned char or int) inside a struct?

I want to use the Microchip TCP/IP stack in my project but they use bits in structs the compiler says it's not available in boostc but what whould be the best solution to replace them with?

Share this post


Link to post
Share on other sites
Dave    0

Tom,

 

Is there anyway to access bits in a variable (unsigned char or int) inside a struct?
You can access individual bits using the dot operator, ie

 

int x;

x.0 = 1; // sets the lsb bit

x.6 = 1; // sets the seventh bit.

 

You can #define a bit name number, ie

 

#define mybit 10

x.mybit = 0;

 

The only way to access groups of bits is to manually mask them in and out.

 

I hope that helps.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×