Skip to main content\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Appendix C Bit-Manipulation Quick Reference
In embedded C, we frequently need to set, clear, or test individual bits in registers.
| Set bit \(n\)
|
REG |= (1U << n); |
| Clear bit \(n\)
|
REG &= ~(1U << n); |
| Toggle bit \(n\)
|
REG ^= (1U << n); |
| Test if bit \(n\) is set |
if (REG & (1U << n)) |
| Test if bit \(n\) is clear |
if (!(REG & (1U << n))) |