[英]Python convert string to decimal
我有一個存儲在變量中的二進制值。 如何將其轉換為十進制值或十六進制值?
t = '0b'+bin(0o202)[::-1][:-2]
所以t的值是
t = '0b01000001'
我需要將t的值轉換為十進制或十六進制。
您可以使用hex()和int() :
hex()
int()
>>> hex(int(t, 2)) # hex '0x41' >>> >>> str(int(t, 2)) # decimal '65'
請注意,默認情況下,整數以十進制表示,這就是為什么最后一行可以正常工作的原因。
[英]Convert String to Decimal in Python
[英]convert decimal to string python
[英]Convert a string to integer with decimal in Python
[英]Python Pandas Subset Hex String, Convert to Decimal
[英]How to convert bytearray in python 2.7 to decimal string?
[英]Convert : hexadecimal string to decimal integer with Python
[英]Convert string to binary, and binary to decimal in Python?
[英]How to convert unicode string to decimal number in python?
[英]convert Unicode string to Decimal - Python 2.7
[英]Convert string to decimal (base 10) in Python
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.