0 Replies - 2072 Views - Last Post: 03 November 2012 - 04:47 AM

#1 TechsterAmAn   User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 0
  • Joined: 01-November 12

Decimal To Binary Converter

Posted 03 November 2012 - 04:47 AM

Description: Converts a number in decimal number system to its binary equivalent using recursion.
# decimal to binary conversion using recursion

n = int(raw_input("Enter a number and I will give you its binary equivalent!n> "))
a = []
def recurConvert(k):
  if k==1:          # base case
    a.append(1)
    a.reverse()
    print a
  else:             # recursive step
    a.append(k%2)
    recurConvert(k/2)

recurConvert(n)


Is This A Good Question/Topic? 0
  • +

Page 1 of 1