I'm a bit confused with the explanation about the >> << bit operators, and I cannot find a good explanation online.
The example they give is this:
0b000001 << 2 == 0b000100 (1 << 2 = 4)
0b000101 << 3 == 0b101000 (5 << 3 = 40)
Right Bit Shift (>>)
0b0010100 >> 3 == 0b000010 (20 >> 3 = 2)
0b0000010 >> 2 == 0b000000 (2 >> 2 = 0)
In the example, the << operator keeps the same amount of digits, but the >> operator causes the loss of a digit (I assume because a "1" got taken off). However when I do the example I write this:
shift_right = 0b1100
shift_left = 0b1
shift_right_again = 0b0010100
Your code here!
shift_right = shift_right >> 2
shift_left = shift_left << 2
shift_right_again = shift_right_again >> 3
And get this:
Variable shift_right_again is asking the system to do the same thing the example showed us... move 0b0010100 to the right by 3, but I am getting 0b10 as the outcome. Even assuming all digits that go to the right disappear (which the example doesn't show), it should still be 0b0010. On top of that, if you look at the shift_right variable, from the example I would assume it would be 0b0011, but instead I got 0b11.
Note: I already completed the exercise, I'm just curious to how this operator works.