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