parent
3a1d21f8cf
commit
fd6449c05c
@ -0,0 +1,31 @@ |
|||||||
|
#include <stdio.h> |
||||||
|
|
||||||
|
typedef struct |
||||||
|
{ |
||||||
|
unsigned int data : 10; // 10비트, 0~1023
|
||||||
|
unsigned int error_code : 6; // 6비트 플래그
|
||||||
|
} DataPacket; |
||||||
|
|
||||||
|
int main() |
||||||
|
{ |
||||||
|
DataPacket packet; |
||||||
|
packet.data = 108; |
||||||
|
packet.error_code = 0; |
||||||
|
|
||||||
|
printf("[Packet] data: %d, error_code: 0x%x\n", packet.data, packet.error_code); |
||||||
|
|
||||||
|
// 에러 감지
|
||||||
|
// 0번째 비트 켜기
|
||||||
|
packet.error_code |= 1; |
||||||
|
printf("[Packet] data: %d, error_code: 0x%x\n", packet.data, packet.error_code); |
||||||
|
|
||||||
|
// 3번째 비트 켜기
|
||||||
|
packet.error_code |= (1 << 3); |
||||||
|
printf("[Packet] data: %d, error_code: 0x%x\n", packet.data, packet.error_code); |
||||||
|
|
||||||
|
// 5번째 비트 켜기
|
||||||
|
packet.error_code |= (1 << 5); |
||||||
|
printf("[Packet] data: %d, error_code: 0x%x\n", packet.data, packet.error_code); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
Loading…
Reference in new issue