在稍微複習自己的電概筆記時,心血來潮的想用python來算算看。
在用google找了一下關鍵字,找了一下。(題外話,發現其實很多網站的文章都是從
python的本家複製過來的。本家果然是python的聖地,萬劍歸宗的地方。irc則是高手暗伏的深淵^_^)
anyway,試了一下,還蠻簡單的,python的oo架構真是方便。不過,我還沒找到如何使用有小數的換算(直接用hex()等會造成syntax error>_<)。或許是因為除了老師出作業外,這種換算很少用吧。當然,也有可能是我笨笨,找不到。
"4.73. How do I specify hexadecimal and octal integers?
To specify an octal digit, precede the octal value with a zero. For example, to set the variable "a" to the octal value "10" (8 in decimal), type:
>>> a = 010
To verify that this works, you can type "a" and hit enter while in the interpreter, which will cause Python to spit out the current value of "a" in decimal:
>>> a
8
Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero, and then a lower or uppercase "x". Hexadecimal digits can be specified in lower or uppercase. For example, in the Python interpreter:
>>> a = 0xa5
>>> a
165
>>> b = 0XB2
>>> b
178
To convert back, use the hex() and oct() builtin functions:
>>> oct(
'010'
>>> hex(17
'0xb2'"
Python FAQ Entry