{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 1 :\n", "\n", "\n", "\"Tableau" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 2 :" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "21" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(0b10101)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "91" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(0x5b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 3 :" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b11010000'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(208)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b11111110000'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(0x7F0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 4 :" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x48f7'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(0b100100011110111)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x8e'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(142)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 5 :" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "a) `00100100` ;\n", "\n", "b) C'est un nombre binaire de huit bits soit un octet ;\n", "\n", "c) $2^8 = 256$ de 00000000 à 11111111 c'est à dire de 0 à 255 ;\n", "\n", "d)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "36" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(0b00100100)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x24'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(0b00100100)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'$'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chr(0b00100100)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "e)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0x54 0x75 0x65 0x72 0x20 0x6c 0x65 0x73 0x20 0x68 0x75 0x6d 0x61 0x69 0x6e 0x73 0x20 0x73 0x61 0x75 0x66 0x20 0x46 0x72 0x79\n" ] } ], "source": [ "message = \"Tuer les humains sauf Fry\"\n", "trame_hex = \"\"\n", "for lettre in message :\n", " trame_hex = trame_hex + \" \" + hex(ord(lettre))\n", "print(trame_hex)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "f)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0x53 0x49 0x2c 0x20 0x63 0x6f 0x6f 0x6c 0x21\n", " 0b1010011 0b1001001 0b101100 0b100000 0b1100011 0b1101111 0b1101111 0b1101100 0b100001\n" ] } ], "source": [ "message = \"SI, cool!\" \n", "trame_bin = \"\"\n", "trame_hex = \"\"\n", "for lettre in message :\n", " trame_hex = trame_hex + \" \" + hex(ord(lettre))\n", " trame_bin = trame_bin + \" \" + bin(ord(lettre))\n", "print(trame_hex)\n", "print(trame_bin)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "g) + 32 en décimal, + 20 en hexadécimal, + 00100000 en binaire" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "65" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ord(\"A\")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "97" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ord(\"a\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 6 :" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b11101100'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(0b10111111+0b00101101)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0xd1e'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(0x1cd+0xb51)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pour aller plus loin :\n", "\n", "- Savoir lire l'heure sur des montres binaires : [https://fr.wikihow.com/lire-une-horloge-%C3%A0-affichage-binaire](https://fr.wikihow.com/lire-une-horloge-%C3%A0-affichage-binaire) ;\n", "\n", "- Apprendre à compter comme les Shadock : [https://youtu.be/lP9PaDs2xgQ](https://youtu.be/lP9PaDs2xgQ) ;" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.1 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.1" }, "vscode": { "interpreter": { "hash": "c813da0d88532624e95401f841607d640ef6d724b81c00ab0d0885f617a921c3" } } }, "nbformat": 4, "nbformat_minor": 4 }