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
This is a discussion on what do these operations do? within the C Programming forums, part of the General Programming Boards category; I am sorry if this is a stupid question but I have looked around and can not find the answer ...
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
When i find myself in times of trouble. mother mary comes to me, speaking words of wisdom, let it be C
Read the Bitwise Operation FAQ. All the information you need is already written up there.
Quzah.
Hope is the first step on the road to disappointment.
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.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.
Last edited by Krak; 01-29-2005 at 02:40 PM.
Very poor choice of words here. OR is not addition, as such it doesn't "add" them together.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?Originally Posted by Thantos