Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

进制之间转换 #9

Open
Sogrey opened this issue Feb 14, 2020 · 1 comment
Open

进制之间转换 #9

Sogrey opened this issue Feb 14, 2020 · 1 comment

Comments

@Sogrey
Copy link
Owner

Sogrey commented Feb 14, 2020

进制之间的转换

# 十进制转换为二进制
print(bin(120))

# 将二进制转为十进制
print(int('0B10110',2))
print(int('10110',2))

# 十六进制转十进制
print(int('0XF35AE',16))
print(int('F35AE',16))

# 十进制转为十六进制
print(hex(54321))

# 十六进制转换为二进制
print(bin(0xF012A))

# 将二进制转换为十六进制
print(hex(0b1101110101))

# 十进制转为八进制
print(oct(1234))
# 将八进制转为十进制
print(int('3213',8))

# 输出仍然是十进制
print(0b11010101 * 0XF12 * 0o432 * 123)
@Sogrey Sogrey added this to Python 基础 in Python QAs Feb 14, 2020
@Sogrey
Copy link
Owner Author

Sogrey commented Feb 14, 2020

#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Python QAs
Python 基础
Development

No branches or pull requests

1 participant