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
cool1205
V2EX  ›  Python

求助, Python , bytes 自增问题

  •  
  •   cool1205 · 2021-03-13 17:47:23 +08:00 · 1563 次点击
    这是一个创建于 1111 天前的主题,其中的信息可能已经有所发展或是发生改变。
    各位大佬,小弟遇到一个技术问题,例如现在有个形式如:b'\xc2\x1d'的 bytes 类型数据,此时程序有个循环,每次循环的时候 bytes 增加 1,例如循环依次,变为:b'\xc2\x1e',再循环依次,变为:b'\xc2\x1f',一直循环到:b'\xff\xff',请问各位大佬有没有比较好的方法告诉我一下,如果没有的话,有没有其他可替代的方案提供小弟参考一下!
    6 条回复    2021-03-13 22:19:20 +08:00
    renmu123
        1
    renmu123  
       2021-03-13 17:55:54 +08:00 via Android   ❤️ 1
    把你的原始需求说出来吧
    lcdtyph
        2
    lcdtyph  
       2021-03-13 18:04:02 +08:00
    seq = b'\xc2\x1d'
    (int.from_bytes(seq, 'big') + 1).to_bytes(len(seq), 'big')
    imn1
        3
    imn1  
       2021-03-13 18:04:38 +08:00
    struct 把 bytes 转 int
    cool1205
        4
    cool1205  
    OP
       2021-03-13 18:18:15 +08:00
    @lcdtyph 大兄弟,你真是厉害!人狠话不多,哈哈
    cool1205
        5
    cool1205  
    OP
       2021-03-13 18:18:42 +08:00
    @lcdtyph 膜拜
    hsfzxjy
        6
    hsfzxjy  
       2021-03-13 22:19:20 +08:00 via Android
    用 bytearray
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2950 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:13 · PVG 23:13 · LAX 08:13 · JFK 11:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.