Search This Blog
Available Codings for Programming of C, C++, PYTHON, JAVA and HTML.
Welcome to Coding 4 Programming
- Get link
- X
- Other Apps
Labels
CONVERSION OF DECIMAL NUMBER TO BINARY, OCTAL AND HEXADECIMAL NUMBER SYSTEM | PYTHON
Python Program of Conversion of Decimal Number to Binary, Octal and Hexadecimal Number System by simple method through user define function.
- def binf(n):
- b=0
- i=0
- while(n!=0):
- r=n%2
- b+=r*(10**i)
- n=n//2
- i+=1
- return b
- def octf(n):
- o=0
- i=0
- while(n!=0):
- r=n%8
- o+=r*(10**i)
- n=n//8
- i+=1
- return o
- def hxdf(n):
- h=[]
- while(n!=0):
- r=n%16
- if(r<10):
- h.append(r)
- if(r==10):
- h.append("A")
- if(r==11):
- h.append("B")
- if(r==12):
- h.append("C")
- if(r==13):
- h.append("D")
- if(r==14):
- h.append("E")
- if(r==15):
- h.append("F")
- n=n//16
- nl=[]
- for i in range(len(h)-1,-1,-1):
- nl.append(h[i])
- return nl
- n=int(input("Enter Decimal Number="))
- bn=binf(n)
- print("Binary Number of",n,"is",bn)
- on=octf(n)
- print("Octal Number of",n,"is",on)
- hn1=hxdf(n)
- ltostr=' '.join(map(str, hn1))
- print("Hexadecimal Number of",n,"is",ltostr)
Output Screen:
- If you have any problem related to this program. Please do comment your Problem or Mail us.
- For illustrating the any concept you can comment by line number.
- Thank you! For more programs do regular visit to Coding 4 Programming.
- Get link
- X
- Other Apps
Labels:
Python
Popular Posts
To Check Prime Number | For Loop | Python
- Get link
- X
- Other Apps
To Check Perfect Number | Function | For Loop | Python
- Get link
- X
- Other Apps
Comments
Post a Comment