In this example we will show how to convert decimal to other data types (Binary / Octal / Hexadecimal) in Python.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Get user input decimal number
num = int(input("please input a num:"))
print("Decimal number is:", num)
print("Convert to binary:", bin(num))
print("Convert to octal:", oct(num))
print("Convert to hexadecimal:", hex(num))
Output:
please input a num:24
Decimal number is: 24
Convert to binary: 0b11000
Convert to octal: 0o30
Convert to hexadecimal: 0x18