Home>Article>Backend Development> python decimal to binary

python decimal to binary

angryTom
angryTom Original
2020-02-06 17:39:30 16360browse

python decimal to binary

python decimal to binary conversion

Use thebin()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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python range usage Next article:python range usage