Bitwise shift help please?

K

knservis

Hi,

can somebody please explain to me what is the difference between right
(or left) shift >> and right shift assign >>= ? Is it only
precidence?

Kosta
 
B

Barry Schwarz

Hi,

can somebody please explain to me what is the difference between right
(or left) shift >> and right shift assign >>= ? Is it only
precidence?

Kosta

unsigned int x = 0x10;

x >> 1;

This statement computes the value of the expression (0x08) and then
discards it.

x >>= 1;

This statement computes the same value but assigns the result to x.


Remove del for email
 
F

Farmer

In other words x>>1; does not alter x?( Answering myself: Off course
it makes perfect sense) Thanks
 
R

Rahul

Hi,

can somebody please explain to me what is the difference between right
(or left) shift >> and right shift assign >>= ? Is it only
precidence?

Kosta

Hi Kosta,
What exactly you have in mind when you attribute the difference
between >> and >>= to precedence?
Can you please elaborate your querry, even though you have got the
answers from the above two responses?
Thanks,
 
S

santosh

Rahul said:
Hi Kosta,
What exactly you have in mind when you attribute the difference
between >> and >>= to precedence?
Can you please elaborate your querry, even though you have got the
answers from the above two responses?
Thanks,

The two statements are not directly comparable, since they're not the
same.
 
E

Eric Sosman

Hi,

can somebody please explain to me what is the difference between right
(or left) shift >> and right shift assign >>= ?

The same as the difference between the addition operator +
and the add-and-assign operator +=.
> Is it only
> precidence?

No, it's more than just precEdence. Both operators perform
a shift (or an add, or whatever), but only the "-and-assign" forms
also do an assignment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top