Python程序将十进制转换为二进制,八进制和十六进制

Here you will get python program to convert decimal to binary, octal and hexadecimal.

在这里,您将获得将十进制转换为二进制,八进制和十六进制的python程序。

Python provides inbuilt functions for conversion of one number system to another.

Python提供了将一个数字系统转换为另一个数字系统的内置函数。

  • Convert decimal to binary using bin() function. In converted binary form 0b is present at the beginning.

    使用bin()函数将十进制转换为二进制。 转换后的二进制格式0b  出现在开始时。

  • Convert decimal to octal using oct() function. In converted octal form 0o is present at the beginning.

    使用oct()函数将十进制转换为八进制。 转换八进制形式0o  出现在开始时。

  • Convert decimal to hexadecimal using hex() function. In converted hexadecimal form 0x is present at the beginning.

    使用hex()函数将十进制转换为十六进制 。 转换后的十六进制形式0x  出现在开始时。

Below program demonstrates that how we can do these conversions.

下面的程序演示了我们如何进行这些转换。

Python程序将十进制转换为二进制,八进制和十六进制 (Python Program to Convert Decimal to Binary, Octal and Hexadecimal)

num = int(input("enter a decimal number: "))
 
print("\nbinary form is ", bin(num))
print("octal form is ", oct(num))
print("hexadecimal form is ", hex(num))

Output

输出量

enter a decimal number: 11

输入十进制数字:11

binary form is 0b1011 octal form is 0o13 hexadecimal form is 0xb

二进制形式为0b1011 八进制形式为0o13 十六进制形式为0xb

Comment below if you have any queries regarding above program.

如果您对以上程序有任何疑问,请在下面评论。

翻译自: https://www.thecrazyprogrammer.com/2017/05/python-program-convert-decimal-binary-octal-hexadecimal.html

  • 9
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值