Skip to content
Snippets Groups Projects
Select Git revision
  • 9cdfdef2524972392d79f09038b8c13ed0e1adbf
  • master default
2 results

LectureNote-bit.py

Blame
  • LectureNote-bit.py 758 B
    Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) 
    [Clang 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license()" for more information.
    >>> a=240
    >>> bin(a)
    '0b11110000'
    >>> a
    240
    >>> a<<2
    960
    >>> a>>2
    60
    >>> bin(a<<2)
    '0b1111000000'
    >>> bin(a>>2)
    '0b111100'
    >>> a=1
    >>> hex(a)
    '0x1'
    >>> hex(a<<1)
    '0x2'
    >>> hex(a<<2)
    '0x4'
    >>> a
    1
    >>> hex(a<<5)
    '0x20'
    >>> b=255
    >>> hex(b)
    '0xff'
    >>> hex(b>>1)
    '0x7f'
    >>> hex(b>>2)
    '0x3f'
    >>> hex(b>>5)
    '0x7'
    >>> c=-255
    >>> hex(c)
    '-0xff'
    >>> hex(c>>1)
    '-0x80'
    >>> hex(c>>2)
    '-0x40'
    >>> hex(c>>5)
    '-0x8'
    >>> bin(-255)
    '-0b11111111'
    >>> a=255
    >>> bin(a)
    '0b11111111'
    >>> bin(-a)
    '-0b11111111'
    >>> a=-1
    >>> bin(a)
    '-0b1'
    >>> 9&10
    8
    >>> 9|10
    11
    >>> 9^10
    3
    >>> 10^9
    3
    >>> a=255
    >>> ~a
    -256
    >>>