Python: unsigned 32 bit bitwise arithmetic

前端 未结 5 1828
花落未央
花落未央 2020-12-05 17:31

Trying to answer to another post whose solution deals with IP addresses and netmasks, I got stuck with plain bitwise arithmetic.

Is there a standard way, in Python,

5条回答
  •  遥遥无期
    2020-12-05 18:01

    You can mask everything by 0xFFFFFFFF:

    >>> m = 0xFFFFFF00
    >>> allf = 0xFFFFFFFF
    >>> ~m & allf
    255L
    

提交回复
热议问题