# Note
Here wer gonna explain Bitmasks & how to use them in C
# Bitmasks: set of (independent) bits
set(1) / unset(0)
Bitmasks are a fundamental concept in computer science and low-level programming, particularly when working with individual bits within data.
- Data is saved as bit information
- can be thought of as tiny switches: on(1) / off(0)
- not seen as a number (int, char, …)
- efficient and compact storage
- data is processed as Boolean Logic
- can use bitwise operators (AND, OR, XOR, NOT) to manipulate bits in bitmask
- A bit saves True (1) / False (0)
# Logic Operations for Bit Masking
# Inverting (not)
- Inverts bitwise (1 → 0, 0 → 1)
- ”~” operator
# AND
- Bitwise logical and
- ”&” operator
# OR
- Bitwise logical or
- ”|” operator
# XOR
- Bitwise logical or
- ”^” operator
# Shift Operations
# Right shift
- ”>>” operator
- ”A >> n” shift right for n digits
- LSBs are dropped
- Leading bits are filled with zeros
- Division by two
- Only positive shift count (compiler dependent)
# Left shift
- ”<<” operator
- ”A << n” shift left for n digits
- MSBs are dropped
- LSBs are filled with zeros
- Multiplication by two
- Only positive shift count (compiler dependent)