An easy problem

Sep 28, 2012 at 5:46pm
Can someone explain me what does "(integer + integer) >> 1" mean ...
Sep 28, 2012 at 6:01pm
">>" in this case is a binary operation, it's moves 1 byte to the right. but is integer is a variable?

CMIIW
Sep 28, 2012 at 6:04pm
edited my post because I was lying -.-'
sorry for disinforming
Last edited on Sep 28, 2012 at 6:14pm
Sep 28, 2012 at 6:16pm
What do you mean by "1 byte to the right"? and integer is not a varuable.
Sep 28, 2012 at 6:26pm
correction:
it's shouldn't "1 byte to the right" but "1 bit to the right. what i mean about this is:

binary expression for 4:

00000100

when you write:

4 >> 1;

the result is:

2

because it shift 1 bit to the right, thus the binary expression is:

00000010

CMIIW
Sep 28, 2012 at 6:31pm
Thank you. Now I understand it.
Sep 28, 2012 at 7:11pm
closed account (zb0S216C)
Note that shifting to the left is equivalent to multiplying by powers of two, and shifting to the right is equivalent to dividing by powers of 2.

Wazzak
Topic archived. No new replies allowed.