乔部落格

世界上有10种人:认识二进制的和不认识二进制的

用python实现进制转换

joe posted @ 2010年4月24日 17:24 in 编程 with tags python , 3396 阅读

调用Python内置int()函数把该字串转为数字。以下为在Python解释器编程环境下的操作示范:

  • 把十六进制的字串转为十进制数字:
        >>>print int('ff', 16)
255
  • 把十进制数字转换为以十六进制表示之字串,可调用内置的hex()函数:
        >>>print hex(255)
0xff
  • 调用BinAscii模块其中的b2a_hex()函数,可把以ASCII编码的文字以十六进制表示:
        >>>import binascii
        >>>print binascii.b2a_hex('A')
41
反之也可把以十六进制表示的文字,换成以ASCII编码的文字:
         >>>print binascii.a2b_hex('41')
A
John 说:
2021年11月07日 20:18

Busting the House valuation myths is the only way to know for sure the correct valuation of a property and use it for individual benefits. Here below are some of the popular myths regarding property valuation. instocenka.ru

Delhi Hotel Escorts 说:
2023年12月20日 19:27

Imagine for a moment that you are <a href ="https://www.royalvvip.in/">Delhi Hotel Escorts</a> experiencing feelings of depression and loneliness.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter