def to_binary(val, expected_length=8):
    """Converts decimal value to binary

    :param val: decimal
    :param expected_length: length of data
    :return: binary value
    """

    val = bin(val)[2:]  # to binary

    while len(val) < expected_length:
        val = "0" + val

    return val