ค่าเทียบเท่าไบนารีของจำนวนทศนิยมได้มาจากการพิมพ์ในลำดับย้อนกลับส่วนที่เหลือของการหารต่อเนื่องกันด้วย 2 วิธีแก้แบบเรียกซ้ำสำหรับการแปลงนี้มีดังต่อไปนี้:
def tobin(x):
strbin=''
if x>1:
tobin(x//2)
print (x%2, end='')
num=int(input('enter a number'))
tobin(num)
To test the output, run above code enter a number25 11001 enter a number16 10000