#define TRUE 1
#define FALSE !TRUE
typedef union
{
unsigned char Container;
struct
{
unsigned char Bit_0 : 1;
unsigned char Bit_1 : 1;
unsigned char Bit_2 : 1;
unsigned char Bit_3 : 1;
unsigned char Bit_4 : 1;
unsigned char Bit_5 : 1;
unsigned char Bit_6 : 1;
unsigned char Bit_7 : 1;
}sub_str;
}type_Bit_Array;
type_Bit_Array Bit_Array;
#define ALL_BITS_ARRAY Bit_Array.Container
#define BIT(b,m) switch(b) \
{ \
case 0: \
Bit_Array.sub_str.Bit_0 = m; \
break; \
case 1: \
Bit_Array.sub_str.Bit_1 = m; \
break; \
case 2: \
Bit_Array.sub_str.Bit_2 = m; \
break; \
case 3: \
Bit_Array.sub_str.Bit_3 = m; \
break; \
case 4: \
Bit_Array.sub_str.Bit_4 = m; \
break; \
case 5: \
Bit_Array.sub_str.Bit_5 = m; \
break; \
case 6: \
Bit_Array.sub_str.Bit_6 = m; \
break; \
case 7: \
default: \
Bit_Array.sub_str.Bit_7 = m; \
break; \
}//switch
int main()
{
unsigned char qwe;
ALL_BITS_ARRAY = 0; // Обнулю все
printf("%d\n",ALL_BITS_ARRAY);
qwe = 0; // Обращаюсь к биту 0 по индексу
BIT(qwe,TRUE); // Ставлю его в 1
printf("%d\n",ALL_BITS_ARRAY);
qwe = 1; // Обращаюсь к биту 1 по индексу
BIT(qwe,TRUE); // Ставлю его в 1
printf("%d\n",ALL_BITS_ARRAY);
BIT(7,TRUE); // Прямоe обращение к биту 7
printf("%d\n",ALL_BITS_ARRAY); // Ставлю его в 1
qwe = 7; // Обращаюсь к биту 0 по индексу
BIT(qwe,FALSE); // Ставлю его в 0
printf("%d\n",ALL_BITS_ARRAY);
}