cont_order

概要

この関数は入力値を任意の桁数の2進数表記に変換する

引数一覧

argument name

type

role

order

int

2進数に変換したい値

rank

int

2進数変換した結果を表記する桁数

戻り値

cont_list(list): 2進数変換後のそれぞれの桁での値を格納したlist
格納されている値の型はint

Python code

def cont_order(order, rank):
    """
    This function converts the input value into a binary representation with an arbitrary number of digits as type list.

    Parameters:
        order: The value to be converted to binary
        rank: The number of digits to represent the binary result

    Returns:
        list: A list that stores the value of each digit in the binary representation.
    """
    by_order = format(order, ('0' + str(rank) + 'b'))
    cont_list = []
    for i in range(len(by_order)):
        cont_list.append(int(by_order[i]))
    return cont_list

実行例

[1]:
import pitbe
[2]:
print(pitbe.cont_order(5, 6))
[0, 0, 0, 1, 0, 1]