null
vuild_
Nodes
Flows
Hubs
Login
MENU
Notifications
Login
⌂
c-lang-advanced
Structure
advanced-pointers
•
Function Pointer
•
Pointer to Pointer
•
Void Pointer
data-structures
•
Linked List
•
Stack & Queue
•
Tree & Graph
algorithms
•
Sorting Algorithms
•
Complexity Analysis
bit-ops
•
Bitwise Operators
•
Bit Fields
•
Bit Tricks
system-prog
•
Process
•
Signal
•
IPC (Inter-Process Communication)
concurrency
•
Threads Basics
•
Mutex & Semaphore
•
Race Condition
optimization
•
Compiler Flags
•
Cache Locality
•
Profiling
design-patterns
•
OOP in C
•
Callback Pattern
•
State Machine
project
•
Mini Shell
•
TCP Echo Server
Flow Structure
Bitwise Operators
10 / 25
Bit Tricks
☆ Star
↗ Full
Bit Fields
#c
#c-lang
#advanced
#bit-ops
#bit-fields
@devpc
|
2026-03-29 13:49:33
|
GET /api/v1/flows/6/nodes/74?fv=1&nv=1
Context:
Flow v1
→
Node v1
1
Views
1
Calls
# Bit Fields > 구조체 비트 필드, 메모리 절약 활용 ## 학습 목표 - 구조체 비트 필드의 선언과 사용법을 이해한다 - 비트 필드로 메모리를 절약하는 패턴을 익힌다 ## 내용 ### 비트 필드 선언 ```c typedef struct { unsigned int is_active : 1; // 1비트 unsigned int permission : 3; // 3비트 (0~7) unsigned int priority : 4; // 4비트 (0~15) } Flags; Flags f; f.is_active = 1; f.permission = 5; f.priority = 10; ``` ### 메모리 절약 비교 ```c // 비트 필드 없이 → 3 * 4 = 12 바이트 struct NoField { int is_active; int permission; int priority; }; // 비트 필드 사용 → 1 + 3 + 4 = 8비트 = 1 바이트 (패딩 포함 4 바이트) typedef struct { unsigned int a:1, b:3, c:4; } WithField; ``` ### 실제 활용: 네트워크 헤더 ```c typedef struct { unsigned int version : 4; unsigned int ihl : 4; unsigned int dscp : 6; unsigned int ecn : 2; unsigned int tot_len : 16; } IPv4Header; ``` ## 참고 - 비트 필드의 실제 레이아웃은 컴파일러와 플랫폼에 따라 다를 수 있다 - 이식성이 중요한 경우 비트 마스킹을 직접 사용하는 것이 안전하다
Bitwise Operators
Bit Tricks
// COMMENTS
ON THIS PAGE
No content selected.