Python program for conversion of the number systems
Decimal to Binary, Octal, and Hexadecimal
codeaft.py
n=int(input("Enter Decimal number ")) print("Binary equivalent ",bin(n)) print("Octal equivalent ",oct(n)) print("Hexadecimal equivalent ",hex(n))
Output
codeaft@codeaft:~$ python3 codeaft.py Enter Decimal number 255 Binary equivalent 0b11111111 Octal equivalent 0o377 Hexadecimal equivalent 0xff
Binary to Decimal, Octal, and Hexadecimal
codeaft.py
n=input("Enter Binary number ") print("Decimal equivalent ",int(n,2)) print("Octal equivalent ",oct(int(n,2))) print("Hexadecimal equivalent ",hex(int(n,2)))
Output
codeaft@codeaft:~$ python3 codeaft.py Enter Binary number 11111111 Decimal equivalent 255 Octal equivalent 0o377 Hexadecimal equivalent 0xff
Octal to Decimal, Binary, and Hexadecimal
codeaft.py
n=input("Enter Octal number ") print("Decimal equivalent ",int(n,8)) print("Binary equivalent ",bin(int(n,8))) print("Hexadecimal equivalent ",hex(int(n,8)))
Output
codeaft@codeaft:~$ python3 codeaft.py Enter Octal number 17 Decimal equivalent 15 Binary equivalent 0b1111 Hexadecimal equivalent 0xf
Hexadecimal to Decimal, Binary, Octal
codeaft.py
n=input("Enter Hexadecimal number ") print("Decimal equivalent ",int(n,16)) print("Binary equivalent ",bin(int(n,16))) print("Octal equivalent ",oct(int(n,16)))
Output
codeaft@codeaft:~$ python3 codeaft.py Enter Hexadecimal number FFFF Decimal equivalent 65535 Binary equivalent 0b1111111111111111 Octal equivalent 0o177777
Comments and Reactions