Skip to main content

Posts

Showing posts with the label binary

Python Program to Convert Decimal to Binary

The decimal numeral system in which numbers are expressed in scales of 10. Whereas the binary numeral system involves expressing numbers in scales of 2. Procedure: Suppose we want to convert decimal number 59 to binary. The number 59 is divided by 2 until the quotient is 1. The remainder(carry) that is accumulated(either 1 or 0) till the last sequence of operation that gives the quotient 1, is taken in the reverse order of creation so as to obtain 111011.  59/2 = 29 (1 is taken as carry)  29/2 = 14 (1 is taken as carry)  14/2 = 7 (1 is taken as carry)  7/2 = 3 (1 is taken as carry)  3/2 = 1 (1 is taken as carry)  So when we reverse the carry, we get 11011. Finally, we place the final quotient at the very beginning of the 11011 to get 111011. Source Code: def dec2bin(num):     """"     Function to convert a decimal number to binary number     """     global wholeList   ...