In C language, the colon structure is used to split the high byte and low byte of a 16-bit number

typedef struct{

uint16_t  high_value:8;

uint16_t low_value:8;

}CODE;

CODE mm;
mm.high_value = 0xaa; 
mm.low_value  = 0x0;

uint16_t bb;
memcpy(&bb,&mm,sizeof(CODE));

//当然也可以反过来使用:

uint16_t bb = 0x12;
memcpy(&mm,&bb,sizeof(CODE));

Compared with the following form of definition, it is more convenient to operate.

typedef struct{

uint8_t  high_value;

uint8_t low_value;

}CODE;

CODE nn;

nn.high_value = 0xAA;

nn.low_value = 0x0;

uint16_t  aa = nn.high_value<<8+nn.low_value;

 

Guess you like

Origin blog.csdn.net/modi000/article/details/112564558