Jump to content


Photo

Bits In Struct


1 reply to this topic

#1 tom 2007

tom 2007

    Regular

  • EstablishedMember
  • Pip
  • 58 posts
  • Gender:Male

Posted 09 April 2011 - 06:14 PM

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?

#2 Dave

Dave

    Super Maniac

  • Administrators
  • PipPipPipPipPip
  • 2,091 posts
  • Gender:Male
  • Location:UK
  • Interests:How things work, Electronics, Software, Cycling.

Posted 10 April 2011 - 07:34 PM

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



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users