Given a decimal number, convert the decimal number to its binary representation.
Sample Output:
number = 10
binary = 1010
number = 14
binary = 1110
Python Implementation Using library function:
Sample Output:
number = 10
binary = 1010
number = 14
binary = 1110
Python Implementation Using library function:
print "Enter the decimal number:" number = int(raw_input()) print bin(number)[2:]
Python Implementation Without using library function:
import sys def PrintBinary(number): if number<=0: return PrintBinary(number/2) sys.stdout.write(str(number%2)) print "Enter the decimal number:" number = int(raw_input()) PrintBinary(number)
Python Implementation Using List reverse:
print "Enter the decimal number" number = int(raw_input()) binary = [] while number>0: binary.append(number%2) number = number / 2 print ''.join(str(x) for x in binary[::-1])