{"id":879,"date":"2022-01-04T11:56:30","date_gmt":"2022-01-04T10:56:30","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/?p=879"},"modified":"2022-01-24T17:49:15","modified_gmt":"2022-01-24T16:49:15","slug":"representation-des-donnees-types-et-valeurs-de-base","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/2022\/01\/04\/representation-des-donnees-types-et-valeurs-de-base\/","title":{"rendered":"Repr\u00e9sentation des donn\u00e9es : types et valeurs de base \ud83d\ude0e"},"content":{"rendered":"\n<p class=\"has-vivid-red-color has-text-color has-background\" style=\"background-color:#ffc0c0\"><strong>I &#8211; \u00c9criture d\u2019un entier positif dans une base b \u2a7e 2<\/strong><\/p>\n\n\n\n<p>Scripts Python \u00e0 tester : https:\/\/colab.research.google.com\/drive\/1R8iAxtC0Ol7CclS74TC-7GY9<a href=\"https:\/\/colab.research.google.com\/drive\/1R8iAxtC0Ol7CclS74TC-7GY9yv51o4hR\" data-type=\"URL\" data-id=\"https:\/\/colab.research.google.com\/drive\/1R8iAxtC0Ol7CclS74TC-7GY9yv51o4hR\">yv51o4hR<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Conversion d&rsquo;un nombre en base 2 avec la fonction bin()<\/strong> :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nombre=21\nbin(nombre)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"75\" height=\"33\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-4.png\" alt=\"\" class=\"wp-image-883\" \/><figcaption><em>Python interpr\u00e8te les nombres commen\u00e7ant par 0b comme des nombres binaires<\/em><\/figcaption><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=0b1100\nprint(a)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"28\" height=\"21\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-5.png\" alt=\"\" class=\"wp-image-886\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Conversion d&rsquo;un nombre en base 16 avec la fonction hex()<\/strong> :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=31\nnombre=hex(a)\nprint(nombre)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"43\" height=\"29\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-6.png\" alt=\"\" class=\"wp-image-891\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=0x1F\nprint(a)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"26\" height=\"30\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-7.png\" alt=\"\" class=\"wp-image-894\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=0x1f+0b1100\nprint(a)<\/pre>\n\n\n\n<p>On trouve 43 car 0*1f = 31 en hexad\u00e9cimal et 0b1100 = 12 en binaire.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>**Convertisseur&nbsp;en&nbsp;base&nbsp;2&nbsp;et&nbsp;16**<\/strong> :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nombre=int(input(\"entier en base 10 : \"))\nprint(\"en base 2 : \"+ str(bin(nombre))[2:])\nprint(\"en base 16 : \"+ str(hex(nombre))[2:])<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"201\" height=\"63\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-8.png\" alt=\"\" class=\"wp-image-900\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def binaire(n):\n           q=n\n           bin=''\n           while q!=0:\n                      r=q%2\n                      q=q\/\/2\n                      bin=str(r)+bin\n           return bin<\/pre>\n\n\n\n<ul><li>on attribue n \u00e0 q<\/li><li>on attribue &lsquo; &lsquo; \u00e0 bin<\/li><li>tant que q est diff\u00e9rent de 0 :<ul><li>r est \u00e9gal au quotient de q\/2<\/li><li>q est \u00e9gal \u00e0 la division euclidienne de q\/2<\/li><li>bin est \u00e9gal \u00e0 r (cha\u00eene de caract\u00e8re) + bin<\/li><\/ul><\/li><li>renvoyer bin<\/li><\/ul>\n\n\n\n<p>==&gt; ce qui permet donc de donner n&rsquo;importe quelle valeur en binaire<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=124\nnombre=binaire(a)\nprint(nombre)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"69\" height=\"30\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-9.png\" alt=\"\" class=\"wp-image-908\" \/><\/figure>\n\n\n\n<p><em>Quel est le plus grand entier naturel cod\u00e9 sur 8 bits ?<\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">n=0b11111111\nprint(n)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"40\" height=\"25\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-10.png\" alt=\"\" class=\"wp-image-911\" \/><\/figure>\n\n\n\n<p>On peut coder 256 entiers sur 8 bits.<\/p>\n\n\n\n<p>Soit 255 +1 pour le 0.<\/p>\n\n\n\n<p>Ou 2^8.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Conversion base b base 10<\/strong> :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def mystere(x,b=2):\n  u = 0\n  for a in x:\n    u = b * u + int(a)\n  return u<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=base10(\"11001\")\nprint(a)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"30\" height=\"25\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-11.png\" alt=\"\" class=\"wp-image-918\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=base10(\"11001\",2)\nprint(a)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"30\" height=\"29\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-12.png\" alt=\"\" class=\"wp-image-920\" \/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a=base10(\"11001\",10)\nprint(a)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"58\" height=\"29\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-13.png\" alt=\"\" class=\"wp-image-922\" \/><\/figure>\n\n\n\n<p>__________________________________________________________________________________<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Combien d\u00e9nombrez-vous d\u2019animaux&nbsp;?<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/10\/animaux.png\" alt=\"L\u2019attribut alt de cette image est vide, son nom de fichier est animaux.png.\" width=\"459\" height=\"237\" \/><\/figure>\n\n\n\n<p>Notre r\u00e9ponse est 18 en repr\u00e9sentation d\u00e9cimale.<\/p>\n\n\n\n<p>On peut pr\u00e9ciser si n\u00e9cessaire&nbsp;: (18)<sub>10<\/sub><\/p>\n\n\n\n<p>On peut \u00e9crire&nbsp;des repr\u00e9sentations diff\u00e9rentes du m\u00eame nombre d\u2019animaux : (18)<sub>10<\/sub>= (00010010)<sub>2<\/sub>= (12)<sub>16<\/sub>= (22)<sub>8<\/sub><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/10\/calcwin19-1.png\" alt=\"\" width=\"188\" height=\"164\" \/><\/figure>\n\n\n\n<p>Avec la calculatrice de Windows 10 en mode programmeur. l\u2019\u00e9criture binaire a \u00e9t\u00e9 compl\u00e9t\u00e9e avec des \u00ab&nbsp;z\u00e9ros&nbsp;\u00bb \u00e0 gauche pour avoir un codage sur 8 bits.<\/p>\n\n\n\n<p>Pour repr\u00e9senter un nombre n en base 10, on doit utiliser 10 caract\u00e8res diff\u00e9rents pour repr\u00e9senter les 10 premiers entiers : 0 1 2 3 4 5 6 7 8 9, et d\u00e9composer les entiers suivants \u00e0 l\u2019aide des puissances de 10 successives.<br>Par exemple, 19 repr\u00e9sente le nombre 1 \u00d7 10<sup>1<\/sup>&nbsp;+ 9 \u00d7 10<sup>0<\/sup><\/p>\n\n\n\n<p>En base 2 (binaire) on a 2 symboles 0 et 1.<\/p>\n\n\n\n<p>En base 16 (hexad\u00e9cimal) on 16 symboles&nbsp;: 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F<\/p>\n\n\n\n<p>La valeur de A est 10 et F est 15.<\/p>\n\n\n\n<p>_________________________________________________________________________________ <\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color\">Un entier naturel est un entier positif ou nul. Pour coder des nombres entiers naturels compris entre 0 et 255, il nous suffira de 8 bits (un octet) . D\u2019une mani\u00e8re g\u00e9n\u00e9rale un codage sur&nbsp;<em>n<\/em>&nbsp;bits pourra permettre de repr\u00e9senter des nombres entiers naturels compris entre 0 et 2<sup>n<\/sup>-1 .<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color\">Chacun des nombres 0 ou 1 de l\u2019\u00e9criture binaire est appel\u00e9 bit.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/10\/bit.png\" alt=\"\" width=\"136\" height=\"53\" \/><\/figure>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">Il est n\u00e9cessaire de fixer la taille de cette suite finie de bits pour coder les entiers naturels en machine.<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">Lorsque les nombres sont repr\u00e9sent\u00e9s par plusieurs octets, la machine doit fixer l\u2019ordre en m\u00e9moire de ces octets. On parle de&nbsp;<a href=\"https:\/\/fr.wikipedia.org\/wiki\/Boutisme\">boutisme<\/a>&nbsp;(ou \u00ab\u00a0endianness\u00a0\u00bb en anglais). La m\u00e9moire des ordinateurs est divis\u00e9es en blocs de 8 bits (soit un octet). Un processeur 64 bits par exemple manipule des paquets de 8 octets, soit 64 bits .<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">Dans une base b, on utilise b symboles distincts pour repr\u00e9senter les nombres. La valeur de chaque symbole doit \u00eatre strictement inf\u00e9rieur \u00e0 b.<\/p>\n\n\n\n<p> _________________________________________________________________________________ <\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#f2295b\">Effectuer cette addition de deux nombres binaires cod\u00e9s sur 8 bits sans faire de conversion. V\u00e9rifier le r\u00e9sultat obtenu en effectuant les conversions.<\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#f2295b\">&nbsp;&nbsp;<strong> (00110011)<sub>2<\/sub>+ (00011100)<sub>2<\/sub><\/strong><\/p>\n\n\n\n<p>==&gt; (01001111) <strong><sub>2<\/sub><\/strong>  = 79<\/p>\n\n\n\n<p>51 + 28 = 79<\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#f2295b\">Recommencer avec cette nouvelle addition.<\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#f2295b\">(<strong>10110011)<sub>2<\/sub>+ (01011100 )<sub>2<\/sub><\/strong><\/p>\n\n\n\n<p>==&gt; (100001111) <strong><sub>2<\/sub><\/strong> = 271<\/p>\n\n\n\n<p>92 + 179 =271<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p>Codage des couleurs en HTML :<\/p>\n\n\n\n<p><a href=\"https:\/\/colab.research.google.com\/drive\/1glD7Mm9HYurOvQTzYXJ5lpi7bPi_fY1N\">https:\/\/colab.research.google.com\/drive\/1glD7Mm9HYurOvQTzYXJ5lpi7bPi_fY1N<\/a><\/p>\n\n\n\n<p><strong>1 &#8211; Construire un dictionnaire qui attribue les valeurs aux symboles hexad\u00e9cimaux<\/strong><\/p>\n\n\n\n<p>&lsquo;Un triplet hexad\u00e9cimal est un nombre hexad\u00e9cimal \u00e0 6 chiffres m\u00e9moris\u00e9 sur trois octets utilis\u00e9 en HTML et dans les feuilles de style en cascade (CSS), et d&rsquo;autres applications, pour repr\u00e9senter les couleurs. Les octets repr\u00e9sentent les composantes rouge, vert et bleu de la couleur.<\/p>\n\n\n\n<p>Un octet repr\u00e9sente l&rsquo;intervalle entre 00 et FF (en notation hexad\u00e9cimale), ou 0 \u00e0 255 en notation d\u00e9cimale. Le triplet hexad\u00e9cimal est form\u00e9 par la concat\u00e9nation de trois octets en notation hexad\u00e9cimale, dans l&rsquo;ordre rouge-vert-bleu. Les trois groupes de deux chiffres hexad\u00e9cimaux se suivent sans espace apr\u00e8s un croisillona. Les z\u00e9ros initiaux, non significatifs, doivent figurer, pour garder le nombre de chiffres dans les triplets \u00e9gal \u00e0 six.<\/p>\n\n\n\n<p>Par exemple, le triplet 0,1,2 devrait \u00eatre repr\u00e9sent\u00e9 par le code #000102&prime;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>2 &#8211; Ecrire une fonction permettant de trouver la repr\u00e9sentation RGB d&rsquo;une couleur \u00e0 partir de la repr\u00e9sentation hexad\u00e9cimale.<\/strong><\/p>\n\n\n\n<p><strong>Effectuez un test avec la couleur lightsalmon ci-dessous.<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.w3schools.com\/colors\/colors_picker.asp\">https:\/\/www.w3schools.com\/colors\/colors_picker.asp<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Corrig\u00e9 <\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#construction d'un dictionnaire\ns = '0123456789ABCDEF'\ndic = {}\nfor i in range(16):\n    dic[s[i]] = i\nprint(dic)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"32\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-14-1024x32.png\" alt=\"\" class=\"wp-image-978\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-14-1024x32.png 1024w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-14-300x9.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-14-768x24.png 768w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-14.png 1054w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\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=\"\">lightsalmon=\"#FFA07A\"<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#convertisseur\ndef color_rgb(color_hexa):\n    red=color_hexa[1:3]\n    R=dic[red[0]]*16+dic[red[1]]\n\n    green=color_hexa[3:5]\n    G=dic[green[0]]*16+dic[green[1]]\n\n    blue=color_hexa[5:7]\n    B=dic[blue[0]]*16+dic[blue[1]]\n    return(R,G,B)<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#test\ncolor_rgb(lightsalmon)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"123\" height=\"32\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-15.png\" alt=\"\" class=\"wp-image-982\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-background\" style=\"background-color:#ffd9be;color:#e47a2f\"><strong>II &#8211; Repr\u00e9sentation binaire d\u2019un entier relatif<\/strong><\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#8daa1b\">Le compl\u00e9ment \u00e0 deux est une technique qui consiste \u00e0 inverser tout les bits de la repr\u00e9sentation binaire d\u2019un nombre entier puis \u00e0 rajouter 1 pour obtenir la repr\u00e9sentation binaire de l\u2019entier relatif oppos\u00e9.<\/p>\n\n\n\n<ul><li>Ecrire 45 en binaire &#8211;&gt; 0b101101<\/li><li>Inverser les bits &#8211;&gt; 010010<\/li><li>Ajouter 1 &#8211;&gt; 010011<\/li><li>Additionner en binaire le nombre obtenu et son compl\u00e9ment \u00e0 2 &#8211;&gt; 010011 + 101100 + 000001<\/li><li>Conclure &#8211;&gt; cela donne le nombre n\u00e9gatif<\/li><\/ul>\n\n\n\n<p class=\"has-text-color\" style=\"color:#329970\">Compl\u00e9ment \u00e0 2 &#8211;&gt; inverser les bits et ajouter 1<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p>Avec la m\u00e9thode du compl\u00e9ment \u00e0 2 pour un codage sur n bits, on dispose d\u2019une repr\u00e9sentations des entiers relatifs dans l\u2019intervalle [-2<sup>n-1<\/sup>,2<sup>n-1<\/sup>-1].<\/p>\n\n\n\n<p>Le compl\u00e9ment \u00e0 2 de 0 sert \u00e0 repr\u00e9senter -2<sup>n-1<\/sup> .<\/p>\n\n\n\n<p>Ainsi sur 8 bits, on dispose des repr\u00e9sentations des entiers compris entre -128 et 127.<\/p>\n\n\n\n<p>\u2022&nbsp;le signe d\u2019un entier en machine est connu gr\u00e2ce \u00e0 son bit de poids fort<br>\u2022&nbsp;l&rsquo;unicit\u00e9 de la repr\u00e9sentation de nombre compris entre&nbsp;-2<sup>n-1&nbsp;<\/sup>et 2<sup>n-1<\/sup>-1&nbsp;;<br>\u2022&nbsp;l\u2019addition des entiers relatifs en compl\u00e9ment \u00e0 deux utilise le m\u00eame<br>algorithme que pour les entiers naturels.<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Comment est repr\u00e9sent\u00e9 -128 cod\u00e9 sur 8 bits ?<\/p>\n\n\n\n<p class=\"has-light-green-cyan-background-color has-text-color has-background\" style=\"color:#00a563\"><strong>3) Repr\u00e9sentation approximative des nombres r\u00e9els<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/01\/image.png\" alt=\"\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/01\/image-1.png\" alt=\"\" \/><figcaption> <\/figcaption><\/figure>\n\n\n\n<p>Un nombre r\u00e9el est constitu\u00e9 de deux parties : la partie enti\u00e8re et la partie fractionnelle (les deux parties sont s\u00e9par\u00e9es par une virgule).<\/p>\n\n\n\n<p>Il existe deux m\u00e9thodes pour repr\u00e9senter les nombre r\u00e9el :<\/p>\n\n\n\n<p>1. Virgule fixe ou la position de la virgule est fixe ;<\/p>\n\n\n\n<p>2. Virgule flottante : la position de la virgule change ( dynamique )<\/p>\n\n\n\n<p>Dans la repr\u00e9sentation en virgule fixe les valeurs sont limit\u00e9es et nous n\u2019avons pas une grande pr\u00e9cision .<\/p>\n\n\n\n<p>En python les nombres r\u00e9els sont repr\u00e9sent\u00e9s par des nombres en virgule flottante de type float.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/10\/iee755-1.png\" alt=\"\" \/><\/figure>\n\n\n\n<ul><li>\u00e9crire -3,3125 en binaire ==&gt; <\/li><li>\u00e9crire 0,25 , 1\/3 puis 0.1 en binaire ==&gt;<\/li><\/ul>\n\n\n\n<p><strong>corrig\u00e9 :<\/strong><\/p>\n\n\n\n<p>http:\/\/yb-isn.fr\/nsi-2020\/wp-content\/uploads\/2020\/12\/No<a href=\"http:\/\/yb-isn.fr\/nsi-2020\/wp-content\/uploads\/2020\/12\/Nombre-1.pdf\" data-type=\"URL\" data-id=\"http:\/\/yb-isn.fr\/nsi-2020\/wp-content\/uploads\/2020\/12\/Nombre-1.pdf\">mbre-1.pdf<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I &#8211; \u00c9criture d\u2019un entier positif dans une base b \u2a7e 2 Scripts Python \u00e0 tester : https:\/\/colab.research.google.com\/drive\/1R8iAxtC0Ol7CclS74TC-7GY9yv51o4hR Conversion d&rsquo;un nombre en base 2 avec la fonction bin() : Conversion d&rsquo;un nombre en base 16 avec la fonction hex() : On trouve 43 car 0*1f = 31 en hexad\u00e9cimal et 0b1100 = 12 en binaire. [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1057,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts\/879"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/comments?post=879"}],"version-history":[{"count":106,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts\/879\/revisions"}],"predecessor-version":[{"id":1058,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts\/879\/revisions\/1058"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/media\/1057"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/media?parent=879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/categories?post=879"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/tags?post=879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}