Hello Folks,

I have this structure
Code:
typedef struct {
   char transLen;
   unsigned short transType; // 8bit
    unsigned short Pparity;
} Buf;
Need your advices .. I need the variable transType to be accessed BITWISE manner in an efficient way. I need all the bits in transType as an individual variables as i will be accessing them very often n later set the PARITY (even or odd) in the Pparity variable for the transType as a whole(parity for the 8 bits). I would also set the parity for the tranLen too in Pparity.

Here are my approaches



Approach 1 :

including the structure like below into Buf instead of transTyp n access indivdual bits
Code:
struct portie {

    unsigned int autfd   : 1;

    unsigned int bldfc   : 1;

    unsigned int undln   : 1;

    unsigned int itals   : 1;
   
    unsigned int cal: 1;

    unsigned int jal   : 1;

    unsigned int mal   : 1;

    unsigned int pal   : 1;

} ;
Approach 2:

Using bitwise operators change the bits of transType without assigning identifiers for the each BIT.

Appraoch 3: Your advices ...

PS : Any approach would have been fine if there isnt any parity calculation

Thank you
Max