{"id":2456,"date":"2020-01-20T11:08:39","date_gmt":"2020-01-20T10:08:39","guid":{"rendered":"https:\/\/icn-isn-boissy.yj.fr\/wp\/?p=2456"},"modified":"2025-04-01T08:41:30","modified_gmt":"2025-04-01T06:41:30","slug":"codage-exercices","status":"publish","type":"post","link":"https:\/\/icn-isn-boissy.yj.fr\/wp\/2020\/01\/20\/codage-exercices\/","title":{"rendered":"Codage &#8211; Exercices"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Exercice 1<\/strong><\/h2>\n\n\n\n<p>Ecrire une fonction <strong>decimal_vers_binaire()<\/strong> qui prend comme argument un nombre entier d\u00e9cimal saisi par l&rsquo;utilisateur et qui renvoi le nombre binaire correspondant sur 1 octet (8bits).<\/p>\n\n\n\n<p>La fonction devra coder le nombre d\u00e9cimal en binaire et rajoutera le nombre de 0 voulu pour faire un octet.<\/p>\n\n\n\n<p><strong>Exemples : <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"529\" height=\"225\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-1.png\" alt=\"\" class=\"wp-image-2458\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-1.png 529w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-1-300x128.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"529\" height=\"224\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-2.png\" alt=\"\" class=\"wp-image-2459\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-2.png 529w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-2-300x127.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Exercice <\/strong>2<\/h2>\n\n\n\n<p>Modifier la fonction pr\u00e9c\u00e9dente pour coder le nombre entier sur 16 bits.<\/p>\n\n\n\n<p><strong>Exemples :<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"532\" height=\"223\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-3.png\" alt=\"\" class=\"wp-image-2460\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-3.png 532w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-3-300x126.png 300w\" sizes=\"auto, (max-width: 532px) 100vw, 532px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"221\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-4.png\" alt=\"\" class=\"wp-image-2461\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-4.png 533w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-4-300x124.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Exercice 3<\/strong><\/h2>\n\n\n\n<p>Ecrire une fonction  <strong>plus_un()<\/strong> qui ajoute 1 \u00e0 un nombre binaire de 8 bits saisi par l&rsquo;utilisateur pass\u00e9 en argument.<\/p>\n\n\n\n<p><strong>Exemples :<\/strong><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"224\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-5.png\" alt=\"\" class=\"wp-image-2463\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-5.png 533w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-5-300x126.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"534\" height=\"217\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-6.png\" alt=\"\" class=\"wp-image-2464\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-6.png 534w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-6-300x122.png 300w\" sizes=\"auto, (max-width: 534px) 100vw, 534px\" \/><\/figure>\n\n\n\n<p>Pour vous aiguiller :<br><strong>1-<\/strong> Recopier l&rsquo;octet saisi par l&rsquo;utilisateur dans une liste.<br><strong>2-<\/strong> Comparer chaque bit, rang par rang. Si le bit de rang 0 est \u00e9gal \u00e0 1, le changer \u00e0 0 et marquer la retenue \u00e0 Vraie. Si le bit de rang 0 est \u00e9gal \u00e0 0, le changer \u00e0 1 et garder les autres intacts.<br><strong>3-<\/strong> Si la retenue est  Vraie tester les bit de rang suivant, les uns apr\u00e8s les autres tant que la retenue est  Vraie.<br><strong>4-<\/strong> Recopie du r\u00e9sultat dans un string que l&rsquo;on affichera en appelant la fonction <strong><em>plus_un()<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exercice 4<\/h2>\n\n\n\n<p> Ecrire un programme qui permet de convertir les nombres entiers  en binaire sign\u00e9 en compl\u00e9ment \u00e0 2 (en 8 bits) . <br> <strong>1- <\/strong>Adapter la fonction  <strong>decimal_vers_binaire<\/strong> <strong>()<\/strong> de l&rsquo;<em><strong>exercice 1<\/strong><\/em> afin de convertir le nombre binaire  en d\u00e9cimal (sur 7 bits). <br><strong>2-<\/strong> Cr\u00e9er une fonction <strong>inversion()<\/strong> qui prend en argument le nombre binaire convertit pr\u00e9c\u00e9demment et renvoi le r\u00e9sultat d&rsquo;une inversion bit \u00e0 bit.<br><strong>3- <\/strong>Utiliser la fonction <strong>plus_un()<\/strong> de l&rsquo;<strong><em>exercice 3<\/em><\/strong> avec comme argument le nombre binaire renvoy\u00e9 par la fonction inversion() et renvoi le r\u00e9sultat de l&rsquo;addition de ce dernier avec 1.<br>Enfin, imprimer \u00e0 l&rsquo;\u00e9cran le r\u00e9sultat et v\u00e9rifier la justesse de ce dernier.<\/p>\n\n\n\n<p><strong>Exemples :<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"531\" height=\"286\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-7.png\" alt=\"\" class=\"wp-image-2466\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-7.png 531w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-7-300x162.png 300w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"292\" src=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-8.png\" alt=\"\" class=\"wp-image-2467\" srcset=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-8.png 528w, https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-content\/uploads\/2020\/01\/image-8-300x166.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Exercice 5<\/h2>\n\n\n\n<p><strong> NoteBook de correction<\/strong><\/p>\n\n\n\n<p><\/p>\n\r\n","protected":false},"excerpt":{"rendered":"<p>Exercice 1 Ecrire une fonction decimal_vers_binaire() qui prend comme argument un nombre entier d\u00e9cimal saisi par l&rsquo;utilisateur et qui renvoi le nombre binaire correspondant sur 1 octet (8bits). La fonction devra coder le nombre d\u00e9cimal en binaire et rajoutera le nombre de 0 voulu pour faire un octet. Exemples : Exercice 2 Modifier la fonction &hellip; <a href=\"https:\/\/icn-isn-boissy.yj.fr\/wp\/2020\/01\/20\/codage-exercices\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">Codage &#8211; Exercices<\/span>  <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[],"class_list":["post-2456","post","type-post","status-publish","format-standard","hentry","category-nsi"],"_links":{"self":[{"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/posts\/2456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/comments?post=2456"}],"version-history":[{"count":7,"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/posts\/2456\/revisions"}],"predecessor-version":[{"id":4268,"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/posts\/2456\/revisions\/4268"}],"wp:attachment":[{"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/media?parent=2456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/categories?post=2456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icn-isn-boissy.yj.fr\/wp\/wp-json\/wp\/v2\/tags?post=2456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}