Posts

Showing posts from August, 2021

Left Shift & Right Shift Operator in C

 X <<Y  This means left shift x by y. e.g 2<<1. So 2 in binary 0010 .After left shifting by 1 it becomes 0100 means 4 in decimal. We can calculate this easily .For left shifting result will be calculated using below formula x*2^y. X>>Y This means right shift x by y. e.g 2>>1. So 2 in binary 0010 .After right shifting by 1 it becomes 0001 means 1 in decimal. We can also calculate this easily .For right shifting result will be calculated using below formula x/2^y. However this formula will not work if the number is negative and if the shifting value is greater than the size of the integer.