{ "cells": [ { "cell_type": "markdown", "id": "25d1eb9b", "metadata": {}, "source": [ "## cont_order" ] }, { "cell_type": "markdown", "id": "7a471991", "metadata": {}, "source": [ "### **Outline**" ] }, { "cell_type": "markdown", "id": "95286660", "metadata": {}, "source": [ "This function converts the input to a binary string with a specified bit length." ] }, { "cell_type": "markdown", "id": "d6b4101c", "metadata": {}, "source": [ "### **Index Lsit**" ] }, { "cell_type": "markdown", "id": "0900d5d3", "metadata": {}, "source": [ "|argument name|type|role|\n", "|---|---|---|\n", "|order|int|The value to be converted to binary|\n", "|rank|int|The number of digits to represent the binary conversion result|" ] }, { "cell_type": "markdown", "id": "a669d811", "metadata": {}, "source": [ "### **Return**" ] }, { "cell_type": "markdown", "id": "02dde6e3", "metadata": {}, "source": [ "cont_list(list):\\\n", "A list that stores the value of each digit after binary conversion.\\\n", "The elements in the list are of type `int`" ] }, { "cell_type": "markdown", "id": "ad335a6d", "metadata": {}, "source": [ "### **Python code**" ] }, { "cell_type": "markdown", "id": "e602a06c", "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", "id": "1c0b9f63", "metadata": {}, "source": [ "### **Sample Run**" ] }, { "cell_type": "code", "execution_count": null, "id": "e6c3038e", "metadata": {}, "outputs": [], "source": [ "import pitbe" ] }, { "cell_type": "code", "execution_count": null, "id": "0a893694", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 0, 0, 1, 0, 1]\n" ] } ], "source": [ "print(pitbe.cont_order(5, 6))" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }