Python Decimal to Binary Conversion. Given a decimal number as input, the task is to write a Python program to convert the given decimal number into equivalent binary number. In this article, we will learn about the solution and approach to solve the given problem statement in Python.

### How To Convert Decimal To Binary Conversion in Python?

```Input : 22
Output :010110```

#### Method #1: Recursive solution

```DecimalToBinary(n):
if n >= 1:
DecimalToBinary(n // 2)
print n % 2```

Below is the implementation of above recursive solution:

```def DecimalToBinary(n):
if n >= 1:
DecimalToBinary(n // 2)
print(n % 2, end='')

# Driver Code
if __name__ == '__main__':
# decimal value
dec = 22
# Calling function
DecimalToBinary(dec)```

Attention Geeks! Strengthen your foundations with the Python Programming and learn the basics. If you have encountered any problem with the Code. Let us know in the Comment section.
{"ft_lang_label":"__label__en","ft_lang_prob":0.715257,"math_prob":0.98566335,"size":888,"snap":"2021-31-2021-39","text_gpt3_token_len":203,"char_repetition_ratio":0.15271494,"word_repetition_ratio":0.056737587,"special_character_ratio":0.25112614,"punctuation_ratio":0.125,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99871445,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,3,null,9,null,6,null,9,null,6,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-22T22:45:19Z\",\"WARC-Record-ID\":\"<urn:uuid:32e3c81a-6191-4e2d-b67c-b8b910f6ea58>\",\"Content-Length\":\"182948\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1708f236-8b1a-4d68-ab04-9198e575d9ee>\",\"WARC-Concurrent-To\":\"<urn:uuid:9db88997-b70f-405b-b737-cac5e34e55bb>\",\"WARC-IP-Address\":\"198.54.120.74\",\"WARC-Target-URI\":\"https://logicalidea.xyz/python-decimal-binary/\",\"WARC-Payload-Digest\":\"sha1:QSRJL6TMICR6DCXGOVZAJHNN6YOML2QJ\",\"WARC-Block-Digest\":\"sha1:ZNSVNNXB52RIJU4YFGQXMN43YMA56JAC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057403.84_warc_CC-MAIN-20210922223752-20210923013752-00517.warc.gz\"}"}