V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jtsai
V2EX  ›  Python

求助: Python 字符串 '0x01' 转换成 数字

  •  
  •   jtsai · 2017-04-21 14:35:17 +08:00 · 3156 次点击
    这是一个创建于 2534 天前的主题,其中的信息可能已经有所发展或是发生改变。

    int('0x01') 报错~~~ 咋办

    7 条回复    2017-04-22 10:39:43 +08:00
    fy
        1
    fy  
       2017-04-21 14:41:32 +08:00   ❤️ 3
    int('0xaa01', 16)
    TerrenceSun
        2
    TerrenceSun  
       2017-04-21 14:56:53 +08:00
    int('0x01',0)
    nyanyh
        3
    nyanyh  
       2017-04-21 15:42:22 +08:00
    struct.pack('i', '0x01')
    Yingruoyuan
        4
    Yingruoyuan  
       2017-04-21 17:53:04 +08:00   ❤️ 1
    int(eval('0x01'))
    aristotll
        5
    aristotll  
       2017-04-21 18:41:15 +08:00
    @Yingruoyuan eval 性能不好吧
    phrack
        6
    phrack  
       2017-04-22 00:47:57 +08:00 via Android
    @aristotll 不用管 eval 的性能吧,谁会代码里到处是 eval 〒_〒
    Yingruoyuan
        7
    Yingruoyuan  
       2017-04-22 10:39:43 +08:00
    @aristotll
    @phrack
    @jtsai
    是的,这个比较适合救急用,楼上的 int('0xaa01', 16)是更好的方法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5344 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:04 · PVG 16:04 · LAX 01:04 · JFK 04:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.