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

求教一个 Python 反码的问题.

  •  
  •   luckyc · Apr 19, 2019 · 2669 views
    This topic created in 2761 days ago, the information mentioned may be changed or developed.

    QQ 截图 20190419143746.png

    如图, 二进制 1101110 如何得出-18 的? 11001 如何得出-7 的

    3 replies  •  2019-04-19 21:38:27 +08:00
    cshlxm
    cshlxm
    Apr 19, 2019
    1
    1101110 去掉头部 1,反码 010001 =17 再+1 =18 第一位的 1 表示是负数 即 -18
    11001 去掉头部 1,反码 0110 =6 再 +1 =7 同理即-7
    fengyuwusong
    fengyuwusong
    Apr 19, 2019
    2
    你这不是补码吗?...

    正数
    源码反码补码都一样

    负数
    反码转源码:符号位不变, 其他按位取反
    补码转源码:符号为不变, 其他按位取反 再加 1

    例如 1101110 => 1010001 + 1 = 1010010 = -1 * (2^1 + 2^4) = -1 * ( 2+16 )= -18
    剩下那个你可以自己试试。
    Leigg
    Leigg
    Apr 19, 2019 via iPhone
    3
    正数的取反刚好是-(x+1)
    负数取反刚好是(-x)-1
    了解原理的话,搜一下二进制 补码
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2088 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:44 · PVG 22:44 · LAX 06:44 · JFK 09:44
    ♥ Do have faith in what you're doing.