cont_order

Outline

This function converts the input to a binary string with a specified bit length.

Index Lsit

argument name

type

role

order

int

The value to be converted to binary

rank

int

The number of digits to represent the binary conversion result

Return

cont_list(list):
A list that stores the value of each digit after binary conversion.
The elements in the list are of type 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

Sample Run

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