Naive methods for decimal to binary conversion
1. Using recursion
1000 10010 111
2. Using the loop
The binary representation of 100 (using loops) is: 001100100
Using bin ()
Using bin () reduces the time required for coding and also removes the difficulties you might see in the above two methods.
Syntax: bin (a) Parameters: a: an integer to convert Return Value: A binary string of an integer or int object. Exceptions: Raises TypeError when a float value is sent in arguments.
The binary representation of 100 (using bin ()) is: 1100100
This article courtesy of Manjit Singh . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you'd like to share more information on the topic discussed above.