I want to move the bits that make up a int
using the operator <<
without the number of bits that make up the integer increasing. For example:
i = 5 #101 en binario
i = i << 2
print bin(i)
I want the bits that make up i
to acquire the 100
corresponding to moving the 3 initial bits. However, what happens is that it adds two zeros to the right, with which the bits of i
are finally 10100
.
I understand that this happens because the binary displacement is analogous to multiplying, hence I add the zeros, but I do not know how to keep the number of bits I want.