I am sorry if this is a stupid question but I have looked around and can not find the answer anywhere.
What do these two operations do?
a |= b
and
a=a>>1
Printable View
I am sorry if this is a stupid question but I have looked around and can not find the answer anywhere.
What do these two operations do?
a |= b
and
a=a>>1
Read the Bitwise Operation FAQ. All the information you need is already written up there.
Quzah.
Those are bitwise operations. The first adds two variables or constants with bitwise OR, and the second shifts a value a certain number of bits. If you don't know how to read binary code, then they're rather useless to you.Quote:
Originally Posted by the_head
Say a=3 and b=5
And the second operation would shift A's bits over 1 place to the right.Code://Not actually code, but whatever.
0011
+0101 //Add using bitwise OR
=0111 //Our result is 7.
0011 >> 1 = 0001
So 3>>1 = 1.
Very poor choice of words here. OR is not addition, as such it doesn't "add" them together.Quote:
The first adds two variables or constants with bitwise OR
True..I kinda like to think of it as "adding with OR"...rather than calling it "OR'ing" them together, eh? ;)Quote:
Originally Posted by Thantos