[英]How do I convert a hexstring to hex?
If I have a string with the following value: 如果我有一个具有以下值的字符串:
STR = "00DE"
how do I convert that so that STR
becomes 0x00DE
? 如何将其转换为
STR
变为0x00DE
? What function do I use? 我要使用什么功能?
If you mean you want STR to be a string in the form you describe, the simplest way is to prepend '0x'
to the string: 如果您想让STR以您描述的形式成为字符串,则最简单的方法是在字符串前添加
'0x'
:
STR = '0x' + STR
If you mean that you want STR to become an integer with the indicated numeric value, then invoke the int()
constructor: 如果您要让STR成为具有指定数字值的整数,请调用
int()
构造函数:
STR = int(STR, 16)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.