{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Binaire" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "En Python, un nombre binaire est préfixé de 0b." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 3 4\n" ] } ], "source": [ "print(0b10 , 0b11 , 0b100)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Conversion de la base binaire à la base décimale : " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "241" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0b11110001" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Conversion de décimale à binaire :" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b11111111'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(255)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Hexadécimal" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "En Python un nombre hexadécimal est préfixé de 0x" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10 11 12 13 14 15\n" ] } ], "source": [ "print(0xA, 0xB, 0xC, 0xD, 0xE, 0XF)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Conversion de la base hexadécimale à la base décimale :" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "179340445" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0xAB0849D" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Conversion de décimale à hexadécimale :" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x100'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(256)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }