{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "38084979",
   "metadata": {},
   "source": [
    "# 04-07 · Переводчик систем счисления\n",
    "\n",
    "Практика к разделу [«Системы счисления»](../../site/chapters/glava-04/04-07-sistemy-schisleniya.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69459505",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить bin(), oct(), hex() и int() с указанием основания."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc0f8122",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8c64ec5c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:18.907275Z",
     "iopub.status.busy": "2026-08-16T10:03:18.907159Z",
     "iopub.status.idle": "2026-08-16T10:03:18.925437Z",
     "shell.execute_reply": "2026-08-16T10:03:18.924963Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b1010\n",
      "0o12\n",
      "0xa\n"
     ]
    }
   ],
   "source": [
    "print(bin(10))\n",
    "print(oct(10))\n",
    "print(hex(10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d77233e1",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Переведите число 255 во все три системы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "088e705c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:18.926402Z",
     "iopub.status.busy": "2026-08-16T10:03:18.926273Z",
     "iopub.status.idle": "2026-08-16T10:03:18.928672Z",
     "shell.execute_reply": "2026-08-16T10:03:18.928211Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b11111111\n",
      "0o377\n",
      "0xff\n"
     ]
    }
   ],
   "source": [
    "n = 255\n",
    "print(bin(n))\n",
    "print(oct(n))\n",
    "print(hex(n))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b5222f7",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "Теперь в обратную сторону: превратите текст `\"FF\"` (hex) и `\"1010\"` (binary) обратно в обычные числа."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b8c92560",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:18.929626Z",
     "iopub.status.busy": "2026-08-16T10:03:18.929511Z",
     "iopub.status.idle": "2026-08-16T10:03:18.932140Z",
     "shell.execute_reply": "2026-08-16T10:03:18.931678Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "255\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "print(int(\"FF\", 16))\n",
    "print(int(\"1010\", 2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb30ca04",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Выведите bin(), oct() и hex() для вашего года рождения."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1a9e0b84",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:18.933088Z",
     "iopub.status.busy": "2026-08-16T10:03:18.932980Z",
     "iopub.status.idle": "2026-08-16T10:03:18.935081Z",
     "shell.execute_reply": "2026-08-16T10:03:18.934704Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b11111011010\n",
      "0o3732\n",
      "0x7da\n"
     ]
    }
   ],
   "source": [
    "year = 2010\n",
    "print(bin(year))\n",
    "print(oct(year))\n",
    "print(hex(year))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "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.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
