Home >Backend Development >Python Tutorial >python decimal to binary
python decimal to binary conversion
Use the bin() function to convert decimal to binary in python .
bin() returns the binary representation of an int or long int.
The following is an example of use:
>>>bin(10) '0b1010' >>> bin(20) '0b10100'
Supplement: Methods of converting decimal to octal and hexadecimal:
# -*- coding: UTF-8 -*- # 获取用户输入十进制数 dec = int(input("输入数字:")) print("转换为八进制为:", oct(dec)) print("转换为十六进制为:", hex(dec))
numerouspython training videos, All on the Python Learning Network, welcome to online learning!
The above is the detailed content of python decimal to binary. For more information, please follow other related articles on the PHP Chinese website!