{"id":2623,"date":"2025-01-27T09:47:56","date_gmt":"2025-01-27T14:47:56","guid":{"rendered":"https:\/\/ve2cuy.com\/420-1c4\/?page_id=2623"},"modified":"2025-03-19T16:22:26","modified_gmt":"2025-03-19T21:22:26","slug":"operations-sur-les-bits","status":"publish","type":"page","link":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/operations-sur-les-bits\/","title":{"rendered":"Op\u00e9rations sur les bits"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"684\" src=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/bitewise-operators-1024x684.png\" alt=\"\" class=\"wp-image-2629\" style=\"width:458px;height:auto\" srcset=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/bitewise-operators-1024x684.png 1024w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/bitewise-operators-300x200.png 300w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/bitewise-operators-768x513.png 768w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/bitewise-operators.png 1054w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading has-text-align-left has-vivid-cyan-blue-color has-text-color has-link-color wp-elements-9c33845e471acc52313f45bd3ca4d1c2\">Les op\u00e9rateurs binaires (bitwise) sont utilis\u00e9s pour manipuler les bits d&rsquo;une variable.<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Voici les principaux op\u00e9rateurs binaires:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>L&rsquo;op\u00e9rateur AND binaire (<code>&amp;<\/code>)<\/strong><\/h3>\n\n\n\n<p>Cet op\u00e9rateur effectue une op\u00e9ration \u00ab\u00a0<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">ET<\/mark><\/strong>\u00a0\u00bb bit \u00e0 bit entre deux entiers. Le r\u00e9sultat est 1 si les deux bits correspondants sont 1, sinon il est 0.<\/p>\n\n\n\n<p><strong>Exemple :<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;arduino.h>\n#define VITESSE_SERIAL 9600\nvoid setup() {\n    Serial.begin(VITESSE_SERIAL);\n    int a = 5;   \/\/ 0101 en binaire\n    int b = 3;   \/\/ 0011 en binaire\n    int result = a &amp; b;  \/\/ 0001 en binaire\n    Serial.println(result);  \/\/ Affiche 1\n}\nvoid loop(){}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>L&rsquo;op\u00e9rateur OR binaire (<code>|<\/code>)<\/strong><\/h3>\n\n\n\n<p>Cet op\u00e9rateur effectue une op\u00e9ration \u00ab\u00a0<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">OU<\/mark><\/strong>\u00a0\u00bb bit \u00e0 bit entre deux entiers. Le r\u00e9sultat est 1 si au moins un des deux bits correspondants est 1, sinon il est 0.<\/p>\n\n\n\n<p><strong>Exemple :<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;arduino.h>\n#define VITESSE_SERIAL 9600\nvoid setup() {\n    Serial.begin(VITESSE_SERIAL);\n    int a = 5;   \/\/ 0101 en binaire\n    int b = 3;   \/\/ 0011 en binaire\n    int result = a | b;  \/\/ 0111 en binaire\n    Serial.println(result);  \/\/ Affiche 7\n}\nvoid loop(){}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>L&rsquo;op\u00e9rateur XOR binaire (<code>^<\/code>)<\/strong><\/h3>\n\n\n\n<p>L&rsquo;op\u00e9rateur \u00ab\u00a0<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">OU exclusif<\/mark><\/strong>\u00a0\u00bb effectue une op\u00e9ration bit \u00e0 bit entre deux entiers. Le r\u00e9sultat est 1 si un seul des deux bits correspondants est 1, mais pas les deux.<\/p>\n\n\n\n<p><strong>Exemple :<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;arduino.h>\n#define VITESSE_SERIAL 9600\nvoid setup() {\n    Serial.begin(VITESSE_SERIAL);\n    int a = 5;   \/\/ 0101 en binaire\n    int b = 3;   \/\/ 0011 en binaire\n    int result = a ^ b;  \/\/ 0110 en binaire\n    Serial.println(result);  \/\/ Affiche 6\n}\nvoid loop(){}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>L&rsquo;op\u00e9rateur NOT binaire (<code>~<\/code>)<\/strong><\/h3>\n\n\n\n<p>Cet op\u00e9rateur effectue une <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">inversion <\/mark><\/strong>de tous les bits de l&rsquo;entier. Tous les 1 deviennent des 0 et tous les 0 deviennent des 1.<\/p>\n\n\n\n<p><strong>Exemple :<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;arduino.h>\n#define VITESSE_SERIAL 9600\nvoid setup() {\n    Serial.begin(VITESSE_SERIAL);\n    int a = 5;   \/\/ 0101 en binaire\n    int result = ~a;  \/\/ 1010 en binaire (en repr\u00e9sentation compl\u00e9ment \u00e0 deux)\n    \/\/ Tester avec unsigned int result\n    Serial.println(result);  \/\/ Affiche -6 (en compl\u00e9ment \u00e0 deux)\n}\nvoid loop(){}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Table de v\u00e9rit\u00e9 des op\u00e9rateurs<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"503\" height=\"316\" src=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/table-de-verite-1.jpg\" alt=\"\" class=\"wp-image-2658\" style=\"width:391px;height:auto\" srcset=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/table-de-verite-1.jpg 503w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/table-de-verite-1-300x188.jpg 300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/figure>\n<\/div>\n\n\n<p>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>Les op\u00e9rateurs de d\u00e9calage (<code>&lt;&lt;<\/code> et <code>&gt;&gt;<\/code>)<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>&lt;&lt;<\/code> (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">d\u00e9calage \u00e0 gauch<\/mark>e)<\/strong> : D\u00e9cale les bits d&rsquo;un nombre vers la gauche, en ajoutant des z\u00e9ros \u00e0 droite.<\/li>\n\n\n\n<li><strong><code>&gt;&gt;<\/code> (<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">d\u00e9calage \u00e0 droite<\/mark>)<\/strong> : D\u00e9cale les bits d&rsquo;un nombre vers la droite, en fonction du signe du nombre (pour les entiers sign\u00e9s).<\/li>\n<\/ul>\n\n\n\n<p><strong>Exemple :<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;arduino.h>\n#define VITESSE_SERIAL 9600\nvoid setup() {\n    Serial.begin(VITESSE_SERIAL);\n    int a = 5;   \/\/ 0101 en binaire\n    int left_shift = a &lt;&lt; 1;  \/\/ D\u00e9calage \u00e0 gauche : 1010 en binaire (10 en d\u00e9cimal)\n    int right_shift = a >> 1; \/\/ D\u00e9calage \u00e0 droite : 0010 en binaire (2 en d\u00e9cimal)\n\n    Serial.print(\"D\u00e9calage \u00e0 gauche : \"); Serial.println(left_shift);  \/\/ Affiche 10\n    Serial.print(\"D\u00e9calage \u00e0 droite : \"); Serial.println(right_shift); \/\/ Affiche 2\n}\nvoid loop(){}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5.1 &#8211; D\u00e9calage et op\u00e9ration sur bits<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;arduino.h>\n#define VITESSE_SERIAL 9600\n#define BIT7 1 &lt;&lt; 7 \/\/ \u00c9quivalent \u00e0 #define BIT7 0b10000000\nvoid setup() {\n    Serial.begin(VITESSE_SERIAL);\n    unsigned int a = 0b10010011;   \/\/ 0101 en binaire\n    \/\/ a &lt;&lt;= 1;  \/\/ \u00c9quivalent \u00e0 a = a &lt;&lt; 1;\n    Serial.println(BIT7); \n\n    if (a &amp; BIT7) {\n      Serial.println(\"Le bit # 7 est \u00e0 ON\");\n    } else\n    {\n      Serial.println(\"Le bit # 7 est \u00e0 OFF\");\n    }\n\n}\nvoid loop(){}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">R\u00e9sum\u00e9 des op\u00e9rateurs de bits :<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Op\u00e9rateur<\/th><th>Signification<\/th><th>Exemple avec <code>a = 5<\/code> et <code>b = 3<\/code><\/th><\/tr><\/thead><tbody><tr><td><code>&amp;<\/code><\/td><td>AND bit \u00e0 bit<\/td><td><code>a &amp; b = 1<\/code><\/td><\/tr><tr><td>|<\/td><td>OR bit \u00e0 bit<\/td><td>a | b = 7<\/td><\/tr><tr><td><code>^<\/code><\/td><td>XOR bit \u00e0 bit<\/td><td><code>a ^ b = 6<\/code><\/td><\/tr><tr><td><code>~<\/code><\/td><td>NOT (inversion des bits)<\/td><td><code>~a = -6<\/code><\/td><\/tr><tr><td><code>&lt;&lt;<\/code><\/td><td>D\u00e9calage \u00e0 gauche<\/td><td><code>a &lt;&lt; 1 = 10<\/code><\/td><\/tr><tr><td><code>&gt;&gt;<\/code><\/td><td>D\u00e9calage \u00e0 droite<\/td><td><code>a &gt;&gt; 1 = 2<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Tableau des assignations<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Symbole<\/th><th>Operateur<\/th><\/tr><\/thead><tbody><tr><td><code>&amp;=<\/code><\/td><td>assignation -&gt; bitwise AND<\/td><\/tr><tr><td><code>|=<\/code><\/td><td>assignation -&gt; bitwise inclusive OR<\/td><\/tr><tr><td><code>^=<\/code><\/td><td>assignation -&gt; bitwise exclusive OR assignment<\/td><\/tr><tr><td><code>&lt;&lt;=<\/code><\/td><td>assignation -&gt; left shift assignment<\/td><\/tr><tr><td><code>&gt;&gt;=<\/code><\/td><td>assignation -&gt; right shift assignment<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>En r\u00e9sum\u00e9, ces op\u00e9rateurs sont puissants pour manipuler directement les bits dans les programmes C, ce qui est utile dans des domaines comme la programmation syst\u00e8me, les syst\u00e8mes embarqu\u00e9s, ou les calculs de bas niveau.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-purple-color has-text-color has-link-color wp-elements-4891d9514f72bdd464404ece3d91d77b\">Rappel &#8211; D\u00e9cimal \u00e0 binaire \u00e0 d\u00e9cimal<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"586\" src=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/DECIMAL_TABLE-1024x586.jpg\" alt=\"\" class=\"wp-image-2640\" style=\"width:607px;height:auto\" srcset=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/DECIMAL_TABLE-1024x586.jpg 1024w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/DECIMAL_TABLE-300x172.jpg 300w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/DECIMAL_TABLE-768x440.jpg 768w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/DECIMAL_TABLE-1536x879.jpg 1536w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/DECIMAL_TABLE.jpg 1972w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Prenons la valeur binaire 0b10011011:<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"460\" height=\"287\" src=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/v4-460px-Convert-from-Binary-to-Decimal-Step-1-Version-5.jpg\" alt=\"\" class=\"wp-image-2643\" srcset=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/v4-460px-Convert-from-Binary-to-Decimal-Step-1-Version-5.jpg 460w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/v4-460px-Convert-from-Binary-to-Decimal-Step-1-Version-5-300x187.jpg 300w\" sizes=\"auto, (max-width: 460px) 100vw, 460px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Conversion vers la base 10 (d\u00e9cimal)<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"460\" height=\"306\" src=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/v4-460px-Convert-from-Binary-to-Decimal-Step-5-Version-5.jpg\" alt=\"\" class=\"wp-image-2644\" srcset=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/v4-460px-Convert-from-Binary-to-Decimal-Step-5-Version-5.jpg 460w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/v4-460px-Convert-from-Binary-to-Decimal-Step-5-Version-5-300x200.jpg 300w\" sizes=\"auto, (max-width: 460px) 100vw, 460px\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-5cb5fad8148563f4b510fa6f818939bb\">D\u00e9monstration avec la calculatrice:<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"985\" src=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/calculatrice-1024x985.png\" alt=\"\" class=\"wp-image-2648\" style=\"width:460px;height:auto\" srcset=\"https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/calculatrice-1024x985.png 1024w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/calculatrice-300x289.png 300w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/calculatrice-768x739.png 768w, https:\/\/ve2cuy.com\/420-1c4\/wp-content\/uploads\/2025\/01\/calculatrice.png 1044w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-left has-vivid-red-color has-text-color has-link-color wp-elements-f91a0bb920c5472b6d69669468b929f1\">6 &#8211; Exemple d&rsquo;impl\u00e9mentation des op\u00e9rateurs binaires<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/*\n  Projet: Op\u00e9rations sur les bits\n  Pour:   Le cours 420-1C4-JR: Objets connect\u00e9s\n  Auteur: Alain Boudreault (aka VE2CUY)\n  Date:   2025.01.27\n  --------------------------------------------------------------------\n  Description:\n\n    Exp\u00e9rimentation avec les op\u00e9rateurs au niveau des bits; \n      &amp; , | , ~ , ^ , &lt;&lt; et >> .\n\n  PlatformIO:\n\n    Rappel: ctrl+alt+b = build\n            ctrl+alt+u = upload\n            ctrl+alt+s = serial terminal\n  --------------------------------------------------------------------\n  M-A-J:\n\n  --------------------------------------------------------------------\n  NOTE: Sous platformio, monitor_speed = 115200\n\n*\/\n\n\/\/ Les d\u00e9clarations\n#include &lt;projet.h>\nvoid afficherBinaire(int nombre, byte nbBits = 8, bool ln = true);\n\n\/\/ D\u00e9but du programme\nvoid setup() {\n  Serial.begin(VITESSE_SERIAL);\n    while (!Serial) {\n    ; \/\/ Attendre que le port s\u00e9rie soit connect\u00e9.\n  }\n  Serial.println(F(\"----> D\u00e9but du programme\\n\"));\n  \n  \/\/ Exemple d'affichage en binaire\n  exempleCompterBinaire();\n\n  \/\/ Exemple de permutations de bits\n  \/\/shiftGauche();\n  \/\/shiftDroite();\n  \n  \/\/ Exemple d'op\u00e9rations logiques sur les bits\n  \/\/exempleOp(AND);\n  \/\/exempleOp(OR);\n  \/\/exempleOp(XOR);\n  \/\/exempleOp(NOT); \n\n  \/\/ Afficher des nombres n\u00e9gatifs en binaire\n  \/\/exempleNegatif();\n\n} \/\/ setup()\n\nvoid loop() { \/\/ Rien \u00e0 faire ici ...\n}\n\n\n\/\/ Impl\u00e9mentation des fonctions\n\/\/=================================================================\nvoid shiftGauche(void) {\n  byte nombre = 0b00000001;\n  Serial.println(F(\"\\n------------------------------------------------------------------\")); \n  Serial.println(F(\"D\u00e9monstration d'une permutation vers la gauche avec l'op\u00e9rateur &lt;&lt; \\n\\n76543210\\n--------\"));\n  afficherBinaire(nombre);\n  for (int n = 1 ; n &lt;= 7; n++) {\n    afficherBinaire(nombre &lt;&lt; n);\n  }\n} \/\/ shiftGauche()\n\n\/\/=================================================================\nvoid shiftDroite(void) {\n  Serial.println(F(\"\\n------------------------------------------------------------------\")); \n  Serial.println(F(\"D\u00e9monstration d'une permutation vers la droite avec l'op\u00e9rateur >> \\n\\n76543210\\n--------\"));\n  byte nombre = 0b10000000;\n  afficherBinaire(nombre);\n  for (int n = 1 ; n &lt;= 7; n++) {\n    afficherBinaire(nombre >> n);\n  }\n} \/\/ shiftDroite()\n\n\n\/\/=================================================================\nvoid exempleOp(operateurBinaire op){\n    \n    int a         = 5;      \/\/ 0101 en binaire\n    int b         = 3;      \/\/ 0011 en binaire\n    int resultat  = 0;\n    String strOp[]  = {\"a &amp; b\", \"a | b\", \"a ^ b \", \"~a\"};\n\n    Serial.println(F(\"\\n------------------------------------\"));  \n    Serial.print(F(\"D\u00e9monstration de \"));\n    Serial.print(strOp[op]);\n    Serial.println(F(\"\\n\\n76543210\\n--------\"));  \n\n    switch (op) {\n    case AND:\n      resultat  = a &amp; b;  \/\/ \/\/ 0001 en binaire\n      break;\n    case OR:\n      resultat  = a | b; \n      break;\n    case XOR:\n      resultat  = a ^ b; \n      break;\n    case NOT:\n      resultat  = ~a; \n      break;\n    default:\n      break;\n    }\n\n    afficherBinaire(a);\n    if (op != NOT) afficherBinaire(b);\n    afficherBinaire(resultat);  \/\/ Affiche 1\n} \/\/ exempleOp()\n\n\n\/\/=================================================================\n\/\/ Voici un exemple simplifi\u00e9 de exempleOp\nvoid exempleAnd(void){\n    Serial.println(F(\"\\n------------------------------------\"));  \n    Serial.println(F(\"D\u00e9monstration de a &amp; b\\n\\n76543210\\n--------\"));  \n    int a         = 5;      \/\/ 0101 en binaire\n    int b         = 3;      \/\/ 0011 en binaire\n    int resultat  = a &amp; b;  \/\/ 0001 en binaire\n    afficherBinaire(a);\n    afficherBinaire(b);\n    afficherBinaire(resultat);  \/\/ Affiche 1\n} \/\/exempleAnd()\n\n\/\/=================================================================\nvoid afficherBinaire(int nombre, byte nbBits, bool ln) {\n  \/\/ NOTE: Utilisation des op\u00e9rateurs sur les bits (>> et &amp;)\n  \/\/ pour afficher le nombre en format binaire.\n  for (int i = nbBits - 1; i >= 0; i--) {\n    Serial.print((nombre >> i) &amp; 1); \n  }\n  if (ln) Serial.println();\n} \/\/ afficherBinaire\n\n\/\/=================================================================\nvoid exempleNegatif(){\n    \/\/ Afficher un nombre n\u00e9gatif en binaire:\n    \/\/ Voir: https:\/\/fr.wikipedia.org\/wiki\/Compl%C3%A9ment_%C3%A0_deux\n  Serial.println(F(\"\\n------------------------------------\"));  \n  for (int i = -5; i &lt; 1 ; i++) {  \n  Serial.print(F(\"\\nAffichage de : \"));\n    Serial.println(i);  \n    afficherBinaire(i, 32);\n  }\n} \/\/ exempleNegatif()\n\n\/\/=================================================================\nvoid exempleCompterBinaire() {\n    \/\/ Compter en binaire (base 2)\n    Serial.println(\"\\n---------------------------------------\"); \n    Serial.println(\"D\u00e9monstration d'un affichage en binaire\\n\\n8421\\n3210\\n----\");\n  for (int i=0; i&lt;= 0b1111; i++) {\n      afficherBinaire(i,4);\n      delay(SECONDE\/2);\n  }\n} \/\/exempleCompterBinaire()\n\n\/\/ FIN DU PROGRAMME<\/pre>\n\n\n\n<p>Fichier projet.h<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#ifndef projet_h\n#define projet_h\n\n#include &lt;arduino.h>\n#define VITESSE_SERIAL  115200\n#define SECONDE         1000\nenum operateurBinaire {\n    AND,    \/\/ &amp;\n    OR,     \/\/ |\n    XOR,    \/\/ ^\n    NOT,    \/\/ ~\n    GAUCHE, \/\/ &lt;&lt;\n    DROITE  \/\/ >>\n};\n\n\/\/ NOTE: Valeur par d\u00e9faut seulement dans le prototype, pas dans l'impl\u00e9mentation\nvoid shiftGauche(void);\nvoid shiftDroite(void);\nvoid exempleOp(operateurBinaire op);\nvoid exempleNegatif();\nvoid exempleCompterBinaire();\n#endif<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7 &#8211; Structures et op\u00e9rations sur bits<\/h2>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">NOTE pour H25<\/mark><\/strong> : Cet exemple est utile pour la r\u00e9alisation du <strong>TP02<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;Arduino.h>\n#include \"Streaming.h\"\n\n#define APP_LED1          0b1 &lt;&lt; 0 \/\/ 0000 0001\n#define APP_LED2          0b1 &lt;&lt; 1 \/\/ 0000 0010\n#define APP_RELAI         0b1 &lt;&lt; 2 \/\/ 0000 0100\n#define APP_MOUVEMENT     0b1 &lt;&lt; 3 \/\/ 0000 1000\n#define ALARM_ARME        0b1 &lt;&lt; 4 \/\/ 0001 0000\n\nstruct Appareils{\n  byte  etatAppareils;  \/\/ Traitement sur les bits.\n  float temperature;\n};\n\nstruct Systeme {\n  byte  codeMessage;\n  byte  heure;\n  byte  minute;\n  byte  seconde;\n  Appareils appareils;\n};\n\nconst char * lesMessages[] = {\n  \"Information sur le syst\u00e8me\",\n  \"Temp\u00e9rature \u00e9lev\u00e9e\",\n  \"Mouvement d\u00e9tect\u00e9\",\n  \"En \u00e9tat de panique\"\n};\n\nSysteme unSysteme = { 1, 10, 10, 59, { 0b00010001, 20.2} };\n\nvoid setup() {\n  Serial.begin(9600);\n  Serial.println(\"D\u00e9but du programme\\n\");\n\n  if (unSysteme.appareils.etatAppareils &amp; ALARM_ARME) {\n    Serial.println(\"Le syst\u00e8me d'alarme est arm\u00e9\");\n  }\n\n  if (unSysteme.appareils.etatAppareils &amp; APP_LED1) {\n    Serial.println(\"La DEL1 est ON\");\n  }\n\n  if (unSysteme.appareils.etatAppareils &amp; APP_LED2) {\n    Serial.println(\"La DEL2 est ON\");\n  } else {\n    Serial.println(\"La DEL2 est OFF\");\n  }\n  Serial &lt;&lt; \"\\nMessage re\u00e7u: \" &lt;&lt; lesMessages[unSysteme.codeMessage] &lt;&lt; endl;\n  Serial &lt;&lt; \"Il est \" &lt;&lt; unSysteme.heure &lt;&lt; \":\" &lt;&lt; unSysteme.minute &lt;&lt; \":\" &lt;&lt; unSysteme.seconde &lt;&lt; endl;\n  }\n\nvoid loop() {\n  \/\/ Rien \u00e0 faire ici ...\n}\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color has-link-color wp-elements-f12d965f1100377f54057a63bed3365d\">8 &#8211; LABORATOIRE &#8211; 45 minutes<\/h2>\n\n\n\n<p><strong>\u00c0 partir des d\u00e9clarations du code source pr\u00e9c\u00e9dent,<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ajouter un champ pour l&rsquo;humidit\u00e9 dans la structure &lsquo;Appareil&rsquo; \n<ul class=\"wp-block-list\">\n<li>renseigner une valeur dans la variable &lsquo;unSysteme.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Remplacer les MACRO par un enum et y ajouter : \n<ul class=\"wp-block-list\">\n<li>APP_BOUTON_PANIQUE<\/li>\n\n\n\n<li>APP_RETRO_LCD<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Remplacer la propri\u00e9t\u00e9 &lsquo;codeMessage&rsquo; par &lsquo;codeEvenement&rsquo;, de type enum, d\u00e9fini par:\n<ul class=\"wp-block-list\">\n<li>evenement_statut_appareils, <\/li>\n\n\n\n<li>evenement_temperature_depassee, <\/li>\n\n\n\n<li>evenement_detection_mouvement, <\/li>\n\n\n\n<li>evenement_bouton_panique, <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Afficher \u00e0 l&rsquo;\u00e9cran,\n<ul class=\"wp-block-list\">\n<li>Grace \u00e0 une boucle, les instructions &amp; et &lt;&lt;, un(des) tableau(x) de chaines (\u00ab\u00a0LED1\u00a0\u00bb, &#8230;), un minimum d&rsquo;instructions;<\/li>\n\n\n\n<li>Et la d\u00e9claration suivante:\n<ul class=\"wp-block-list\">\n<li><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">Systeme unSysteme = { evenement_detection_mouvement, 10, 10, 59, { 0b01010101, 20.2, 45.25} };<\/mark><\/em><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>L&rsquo;\u00e9tat de tous les appareils sous la forme suivante:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Information sur le syst\u00e8me\n\nIl est 10:10:59\n\nCode \u00e9v\u00e9nement: evenement_detection_mouvement\n\n\u00c9tat des appareils en binaire: 01010101 \/\/ Voir la fonction dans l'exemple 6\n\nAppareil: LED1 -                \ud83d\udfe2\nAppareil: LED2 -                \ud83d\udd34\nAppareil: RELAI -               \ud83d\udfe2\nAppareil: Mouvement -           \ud83d\udd34\nAppareil: Alarme -              \ud83d\udfe2\nAppareil: Bouton panique -      \ud83d\udd34\nAppareil: R\u00e9tro-\u00e9clairage -     \ud83d\udfe2\n\nTemp\u00e9rature: 20.20\u00b0C\nHumidit\u00e9   : 45.25%\n<\/pre>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">NOTE<\/mark><\/strong>: Il est possible de r\u00e9aliser ce labo sans l&rsquo;enum &lsquo;Appareil&rsquo; <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Les op\u00e9rateurs binaires (bitwise) sont utilis\u00e9s pour manipuler les bits d&rsquo;une variable. Voici les principaux op\u00e9rateurs binaires: 1. L&rsquo;op\u00e9rateur AND binaire (&amp;) Cet op\u00e9rateur effectue une op\u00e9ration \u00ab\u00a0ET\u00a0\u00bb bit \u00e0 bit entre deux entiers. Le r\u00e9sultat est 1 si les deux bits correspondants sont 1, sinon il est 0. Exemple : 2. L&rsquo;op\u00e9rateur OR binaire [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ub_ctt_via":"","footnotes":""},"class_list":["post-2623","page","type-page","status-publish","hentry"],"featured_image_src":null,"_links":{"self":[{"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/pages\/2623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/comments?post=2623"}],"version-history":[{"count":39,"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/pages\/2623\/revisions"}],"predecessor-version":[{"id":3354,"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/pages\/2623\/revisions\/3354"}],"wp:attachment":[{"href":"https:\/\/ve2cuy.com\/420-1c4\/index.php\/wp-json\/wp\/v2\/media?parent=2623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}