I wonder why adding one or multiple leading zeros to an integer in Python leads to different results when using the bitshift-operators:
In: 10<<1
Out: 20
Adding a "0" in front of the integer:
In: 010<<1
Out: 16
I wonder why adding one or multiple leading zeros to an integer in Python leads to different results when using the bitshift-operators:
In: 10<<1
Out: 20
Adding a "0" in front of the integer:
In: 010<<1
Out: 16
Meanwhile, I found the answer is quite simple - but maybe it's worth sharing it:
According to this answer, adding a leading zero to an integer will cause Python to interpret it as an octal/base 8.
In: int("010",8)
Out: 8
Thus, left-shifting the octal (or decimal 8), i.e. multipicaton by 2**1, leads to 16
In: 8<<1
Out: 16