{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# cont_order" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 概要" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "この関数は入力値を任意の桁数の2進数表記に変換する" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 引数一覧" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "|argument name|type|role|\n", "|---|---|---|\n", "|order|int|2進数に変換したい値|\n", "|rank|int|2進数変換した結果を表記する桁数|" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 戻り値" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "cont_list(list):\n", " 2進数変換後のそれぞれの桁での値を格納したlist\\\n", " 格納されている値の型はint" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Python code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```python\n", "def cont_order(order, rank):\n", " \"\"\"\n", " This function converts the input value into a binary representation with an arbitrary number of digits as type list.\n", "\n", " Parameters:\n", " order: The value to be converted to binary\n", " rank: The number of digits to represent the binary result\n", "\n", " Returns:\n", " list: A list that stores the value of each digit in the binary representation.\n", " \"\"\"\n", " by_order = format(order, ('0' + str(rank) + 'b'))\n", " cont_list = []\n", " for i in range(len(by_order)):\n", " cont_list.append(int(by_order[i]))\n", " return cont_list\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 実行例" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pitbe" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 0, 0, 1, 0, 1]\n" ] } ], "source": [ "print(pitbe.cont_order(5, 6))" ] } ], "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.11.6" } }, "nbformat": 4, "nbformat_minor": 2 }