Python program for conversion of the number systems
Decimal to Binary, Octal, and Hexadecimal
kw.py
n=int(input("Enter Decimal number "))
print("Binary equivalent ",bin(n))
print("Octal equivalent ",oct(n))
print("Hexadecimal equivalent ",hex(n))
Output
kodingwindow@kw:~$ python3 kw.py
Enter Decimal number 255
Binary equivalent 0b11111111
Octal equivalent 0o377
Hexadecimal equivalent 0xff
Binary to Decimal, Octal, and Hexadecimal
kw.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
kodingwindow@kw:~$ python3 kw.py
Enter Binary number 11111111
Decimal equivalent 255
Octal equivalent 0o377
Hexadecimal equivalent 0xff
Octal to Decimal, Binary, and Hexadecimal
kw.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
kodingwindow@kw:~$ python3 kw.py
Enter Octal number 17
Decimal equivalent 15
Binary equivalent 0b1111
Hexadecimal equivalent 0xf
Hexadecimal to Decimal, Binary, Octal
kw.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
kodingwindow@kw:~$ python3 kw.py
Enter Hexadecimal number FFFF
Decimal equivalent 65535
Binary equivalent 0b1111111111111111
Octal equivalent 0o177777
Advertisement