[C언어] 구조체 비트 필드


[C언어] 구조체 비트 필드

ㅇ비트필드의 구조 struct 구조체이름 { 정수자료형 멤버이름 : 비트수; }; * 실수 자료형은 비트 필드로 사용할 수 없다. ㅇexample #include struct Flags { unsigned int a : 1; // a는 1비트 크기 unsigned int b : 3; // b는 3비트 크기 unsigned int c : 7; // c는 7비트 크기 }; int main() { struct Flags f1; // 구조체 변수 선언 f1.a = 1; // 1: 0000 0001, 비트 1개 f1.b = 15; // 15: 0000 1111, 비트 4개 f1.c = 255; // 255: 1111 1111, 비트 8개 printf("%u\n", f1.a); // 1: 1, 비트 1개만 저장됨 ..


원문링크 : [C언어] 구조체 비트 필드