python decimal to binary

angryTom
Release: 2020-02-06 17:39:30
Original
16359 people have browsed it

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'
Copy after login

Supplement: Methods of converting decimal to octal and hexadecimal:

# -*- coding: UTF-8 -*-
 
# 获取用户输入十进制数
dec = int(input("输入数字:"))

print("转换为八进制为:", oct(dec))
print("转换为十六进制为:", hex(dec))
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!