推荐学习书目
› 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
cool1205
V2EX  ›  Python

求助, Python , bytes 自增问题

  •  
  •   cool1205 · Mar 13, 2021 · 2781 views
    This topic created in 2029 days ago, the information mentioned may be changed or developed.
    各位大佬,小弟遇到一个技术问题,例如现在有个形式如:b'\xc2\x1d'的 bytes 类型数据,此时程序有个循环,每次循环的时候 bytes 增加 1,例如循环依次,变为:b'\xc2\x1e',再循环依次,变为:b'\xc2\x1f',一直循环到:b'\xff\xff',请问各位大佬有没有比较好的方法告诉我一下,如果没有的话,有没有其他可替代的方案提供小弟参考一下!
    6 replies  •  2021-03-13 22:19:20 +08:00
    renmu123
        1
    renmu123  
       Mar 13, 2021 via Android   ❤️ 1
    把你的原始需求说出来吧
    lcdtyph
        2
    lcdtyph  
       Mar 13, 2021
    seq = b'\xc2\x1d'
    (int.from_bytes(seq, 'big') + 1).to_bytes(len(seq), 'big')
    imn1
        3
    imn1  
       Mar 13, 2021
    struct 把 bytes 转 int
    cool1205
        4
    cool1205  
    OP
       Mar 13, 2021
    @lcdtyph 大兄弟,你真是厉害!人狠话不多,哈哈
    cool1205
        5
    cool1205  
    OP
       Mar 13, 2021
    @lcdtyph 膜拜
    hsfzxjy
        6
    hsfzxjy  
       Mar 13, 2021 via Android
    用 bytearray
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2217 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 05:12 · PVG 13:12 · LAX 22:12 · JFK 01:12
    ♥ Do have faith in what you're doing.