1 byte? uint8_t
2 bytes? uint 16_t
4 bytes? uint32_t
Eight bytes? uint64_t
See blogs.com/bauchun968/archive/20110/19/2218008.html for details.
The sentence bit0: 1 defines a bit field, bit0 is the domain name of the bit field, and bit0 occupies only one bit.
Bit field means that when storing information, you don't need to occupy a whole byte. But only a few or one binary bit. In order to save storage space and make processing simple, C language provides a data structure called "bit field" or "bit segment". The so-called "bit field" is to divide the binary in a byte into several different regions. And explain the number of digits in each area. Each domain has a domain name, which allows you to operate through the domain name in the program. ? In this way, several different objects can be represented by a binary bit field of one byte.
Reference:/question/391684179.html.
Therefore, in the above structure, an element attribute occupies one bit, which is preceded by two bytes and followed by two bytes. There is no difference in essence, is there?
Usually, you can test the above code like this.
# include & ltstdio.h & gt
Typedef unsigned short integer uint16 _ t;
Typedef unsigned character uint8 _ t;
Typedef structure
{
uint 16 _ t bit 0: 1;
uint 16 _ t bit 1: 1;
uint 16 _ t bit 2: 1;
uint 16 _ t bit 3: 1;
uint 16 _ t bit 4: 1;
uint 16 _ t bit 5: 1;
uint 16 _ t bit 6: 1;
uint 16 _ t bit 7: 1;
uint 16 _ t bit 8: 1;
uint 16 _ t bit 9: 1;
uint 16 _ t bit 10: 1;
uint 16 _ t bit 1 1: 1;
uint 16 _ t bit 12: 1;
uint 16 _ t bit 13: 1;
uint 16 _ t bit 14: 1;
uint 16 _ t bit 15: 1;
} bits 16 1;
Typedef structure
{
uint 8 _ t bit 0: 1;
uint 8 _ t bit 1: 1;
uint 8 _ t bit 2: 1;
uint 8 _ t bit 3: 1;
uint 8 _ t bit 4: 1;
uint 8 _ t bit 5: 1;
uint 8 _ t bit 6: 1;
uint 8 _ t bit 7: 1;
uint 8 _ t bit 8: 1;
uint 8 _ t bit 9: 1;
uint 8 _ t bit 10: 1;
uint 8 _ t bit 1 1: 1;
uint 8 _ t bit 12: 1;
uint 8 _ t bit 13: 1;
uint 8 _ t bit 14: 1;
uint 8 _ t bit 15: 1;
} bits 162;
int main(){
printf("%d,%d ",sizeof(BITS 16 1),sizeof(bits 162));
Returns 0;
The output is 2,2, which means that the structure is two bytes. But what if typedef? Not signed? int? uint 16_t? ; ? That is to say, uint 16_t is represented by the usual 4-byte integer? , the above structure must be at least int length? , the output is 4,2.