bit_manipulation_101
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| bit_manipulation_101 [2021/05/09 17:57] – créée ptitfrap | bit_manipulation_101 [2021/05/10 07:24] (Version actuelle) – ptitfrap | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | OR: | + | ====== Bit Manipulation 101 ====== |
| - | X | 1 = 1 | + | |
| + | ==== OR ==== | ||
| + | pour mettre un bit a 1 | ||
| + | <sxh cpp> | ||
| X | 0 = X | X | 0 = X | ||
| + | X | 1 = 1 | ||
| + | </ | ||
| + | ==== AND ==== | ||
| + | pour mettre un bit a 0 | ||
| + | <sxh cpp> | ||
| + | X & 0 = 0 | ||
| + | X & 1 = X | ||
| + | </ | ||
| + | ==== SNIPPETS ==== | ||
| + | <sxh cpp> | ||
| + | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | ||
| + | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | ||
| + | </ | ||
| + | |||
| + | ==== FLAG ==== | ||
| + | <sxh cpp> | ||
| + | uint8_t FLAGS = 0; | ||
| + | |||
| + | #define F_f1 0 | ||
| + | #define F_f2 1 | ||
| + | #define F_f3 2 | ||
| + | #define F_f4 3 | ||
| + | |||
| + | sbi(FLAGS, | ||
| + | |||
| + | if (FLAGS & _BV(F_f1)) //si flag ON | ||
| + | |||
| + | if (!(FLAGS & _BV(F_f2))) //si flag OFF | ||
| + | |||
| + | cbi(FLAGS, | ||
| + | </ | ||
| + | |||
| + | |||
bit_manipulation_101.1620575870.txt.gz · Dernière modification : 2021/05/09 17:57 de ptitfrap
