Posts

<< Bitwise Left Shift in Python

Image
Hi Python Buddies, Hope you are doing well. I would like to clear the general confusion caused during the understanding of the Bitwise Left Shit(<<) . Before understanding the Bitwise Left shift, we need to understand the basics of Binary Notation of decimal Number system that we use. In the above table, you can see that to represent the number from 0-15, 4 bits are enough; whereas to represent the numbers from 16-20 we need an extra bit(5th bit). I hope you are all aware of how to convert the given decimal number to the binary number. Now let's understand the Bitwise Left Shift(<<) x1 = 3 x1 = x1 << 2    #This means,  3 is  Left bit shifted 2 times print(x1) x2 = 3 x2 << = 2      #This also means,  3 is  Left bit shifted 2 times print(x2) the output is: 12 12 Let's understand how the output gets to 12. The 4-bit Binary equivalent of  3 in our example is 0011 . Bitwise left shift   n times meaning, we have to remove n