litex/miscope/tools/conv.py

12 lines
145 B
Python
Raw Normal View History

2012-09-09 17:46:26 -04:00
def dec2bin(d, nb=0):
2012-08-26 14:56:56 -04:00
if d=="x":
return "x"*nb
elif d==0:
b="0"
else:
b=""
while d!=0:
b="01"[d&1]+b
d=d>>1
2012-09-09 14:38:01 -04:00
return b.zfill(nb)