def dec2bin(d, nb=8):
    """
        Convert dec to binary
    """
    if d == 0:
        return "0".zfill(nb)
    if d < 0:
        d += 1 << nb
    b = ""
    while d != 0:
        d, r = divmod(d, 2)
        b = "01"[r] + b
    return b.zfill(nb)