Cocept of right shift


#1



https://www.codecademy.com/en/courses/python-intermediate-en-KE1UJ/1/1?curriculum_id=4f89dab3d788890003000096


Hello
I don't understand the concept of the right shift.What does it do? And how?
I searched it and I found those pictures below for the 2 types of shift, which one is the type that we use?:



And can you tell me why 1100 after the right shift turn into 11?
I just think that it should return to 1110 according to the second picture.
Can anyone show me with a picture how dose it work?
Thanks for answers. :relaxed:

Replace this line with your code.


#2

shifting to the right means moving to the right by the number written like that:

shift_right = 0b1100
shift_left = 0b1

# Your code here!
shift_right = shift_right >> 2
shift_left = shift_left << 2

print bin(shift_right)
print bin(shift_left)

the result will be:
0b11
0b100
notice the difference between the values of shift_right
shift_left and the result
the observation that >> right shift which makes the numbers move to the right while the << left shift makes the number move to the left
the number written here is 2 so we move 2 to the right or two to the left


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.