Slide to the Left! Slide to the Right!

<Below this line, add a link to the exact exercise that you are stuck at.>
https://www.codecademy.com/courses/python-intermediate-en-KE1UJ/1/1?curriculum_id=4f89dab3d788890003000096#
<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>
I don’t understand how to do this exercise? Could someone help me?

```python

shift_right = 0b1100
shift_left = 0b1

Your code here!

print bin(shift_right >> 2)
print bin(shift_left)

<do not remove the three backticks above>

Think in terms of decimal, which is something we’re quite used to. Say we have a number in the one’s column,

9

When we multiply that by 10 we get,

90

By 10 again, we get,

900

For each magnitude we are shifting the one’s digit to the left without changing the digit. We just add a zero on the right.

Now look at this same concept in terms of binary. We can only have one value representation, 1. Zero is undefined, so let’s stick with the bit.

0b1

This time we are multiplying by 2 since that is the base, just as 10 is above.

0b10

And by 2 again,

0b100

And so on. Again, each change in magnitude was a shift to the left of the bit.

1 Like

Off topic

So technically there is no such thing as, 0b0, only 0 without any special prefix, nomenclature or units. 0.0 does not exist. 0px often shows up in CSS. Again, meaningless. Zero is only zero, undefined. All we know about it is its position in the real number line. The zero of y = x ** 2.

Obviously we can list an infinite number of functions with 0 as their zero. y = - ( x ** 2 ) and y = abs( x ) come to mind, for starters. This is only food for thought in terms of 0.

It is technically a convenience that we can treat zero with such definiteness when it is undefined to begin with. In real terms, x in the quadratic and the absolute equations is approaching zero, on the one hand from the left, the negative, and on the other from the right, the positive. Zero is the limiting value for each domain.

Ah i passed it. Thank you so much :smiley:

1 Like