Search code examples
pythonpython-3.xbitwise-operators

& operator with numbers


I found out something interesting in Python. When I input: 99 & 100 Out is 96. What does '&' do with these numbers? Why is the answer '96'? It looks so wierd...

Thank you in advance!


Solution

  • It's a bitwise operator. The manipulated unit is the binary representation of the numbers

    examples

    3 10
    5 11 &
    ------
    3 10 =
    

    and

    2 01
    3 10 &
    ------
    0 00 =
    

    Do the same for 99 & 100, you'll get out 96 in binary