def bfmt(num, size=8):
    """ Returns the printable string version of a binary number <num> that's length <size> """

    if num > 2**size:
        return format((num >> size) & (2**size - 1), 'b').zfill(size)
    try:
        return format(num, 'b').zfill(size)
    except ValueError:
        return num