1
0

Conversion to YAML
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-07-28 14:42:22 +02:00
parent a6ca16976a
commit 22a59363f0
6 changed files with 111 additions and 143 deletions

View File

@ -4,6 +4,7 @@ subtitle: "Tips and trick for embedded C/C++"
summary: "Tips and trick for embedded C/C++"
date: 2020-06-13T19:01:19+02:00
highlight: true
math: true
---
# Set a bit
@ -53,12 +54,21 @@ output = input << 3; // Multiply by 8
output = (0b1 << X) -1;
```
# Minimum required bits
$$bits = { log(number) \over log(2) }$$
Since you can not use fractions of a bit the number should be rounded up.
# Miscellaneous
```c
// Check if number is ODD
if( (num & 1) == 1) {};
// Flip signed integer
num = ~num + 1;
// Power of two
// Is an integer a power of two?
num > 0 && (num & (num - 1)) == 0;
//Clear all bits from 0 to N
mask = ~((1 << n+1 ) - 1);
x &= mask;
```