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

python 中负数的与运算为什么不对?-1&2 = 2

  •  
  •   nayihz · Jun 3, 2015 · 4434 views
    This topic created in 3997 days ago, the information mentioned may be changed or developed.
    版本Python 2.7。
    (-1)&2,(-1)&(2)都试过了,结果都是2,不知为何?
    5 replies    2015-06-11 14:26:08 +08:00
    ayang23
        1
    ayang23  
       Jun 3, 2015
    没看出哪不对,-1所有的位都是1,和任何数字与运算结果都是那个数字
    lilydjwg
        2
    lilydjwg  
       Jun 3, 2015
    我没看出来哪里不对了……你觉得它的结果是多少才对呢?
    nayihz
        3
    nayihz  
    OP
       Jun 3, 2015
    @ayang23
    @lilydjwg
    不好意思各位,脑子进水了。负数的二进制需要取反再加1。
    艾玛,丢人丢大了。
    weyou
        4
    weyou  
       Jun 3, 2015
    因为结果本来就是2
    mhohai
        5
    mhohai  
       Jun 11, 2015
    很2很2
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3406 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 10:56 · PVG 18:56 · LAX 03:56 · JFK 06:56
    ♥ Do have faith in what you're doing.