如何将数字转换为十六进制数? [英] How to convert a number to hex number?
问题描述
我尝试这个命令:
import string
string.atoi('''78'',16)
这是120而不是4E。
有人可以分辨我如何将十进制数转换为十六进制数?可以
打印A,B,C,DEF。
谢谢。
嗨!
尝试hex:hex(120)
''0x78''
考虑转换字符串 - > int使用int() - function:print int .__ doc __
int(x [,base]) - >整数
如果可能,将字符串或数字转换为整数。一个浮点
参数将被截断为零(这不包括字符串
表示浮点数!)转换字符串时,使用
可选基数。转换
非字符串时提供基数是错误的。如果参数超出整数范围,则会返回一个长对象
。
Daniel
< blockquote> Hako写道:
我尝试这个命令:
import string
string.atoi('''78'',16)
120
这是120而不是4E。
有人可以告诉我如何将十进制数转换为十六进制数?可以打印A,B,C,DEF。
要打印整数的十六进制字符串表示,n,使用
print hex(n)
或
print"%x" %n
问候,
Aaron Bingham
和如果你只想要十六进制数,请尝试:hex(255)[2:]
''ff''
I try this command:
import string
string.atoi(''78'',16)
120
this is 120 not 4E.
Someone can tell me how to convert a decimal number to hex number? Can
print A, B, C,DEF.
Thank you.
Hi!
Try hex:hex(120) ''0x78''
Consider converting string -> int using the int()-function: print int.__doc__
int(x[, base]) -> integer
Convert a string or number to an integer, if possible. A floating point
argument will be truncated towards zero (this does not include a string
representation of a floating point number!) When converting a string, use
the optional base. It is an error to supply a base when converting a
non-string. If the argument is outside the integer range a long object
will be returned instead.
Daniel
Hako wrote:
I try this command:import string
string.atoi(''78'',16)
120
this is 120 not 4E.
Someone can tell me how to convert a decimal number to hex number? Can
print A, B, C,DEF.
To print the hexidecimal string representation of an integer, n, use
print hex(n)
or
print "%x" % n
Regards,
Aaron Bingham
And if you want only the hex number, try:hex(255)[2:]
''ff''
这篇关于如何将数字转换为十六进制数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!