By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

What does this statement yield?

P: n/a
I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.
phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}

Jul 29 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* Frank:
I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.
phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}


For integer types '&3' is effectively the same as '%4'.

I.e. for such types the code should yield 101%4 = 1.

If 'phase' is of a user-defined type then nothing can be said.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 29 '05 #2

P: n/a

"Alf P. Steinbach" <al***@start.no> wrote in message
news:42****************@news.individual.net...
* Frank:
I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.
phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}


For integer types '&3' is effectively the same as '%4'.

I.e. for such types the code should yield 101%4 = 1.

If 'phase' is of a user-defined type then nothing can be said.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Thank you. Understood.

Jul 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.