| View previous topic :: View next topic |
| Author |
Message |
Frank Guest
|
Posted: Fri Jul 29, 2005 5:32 am Post subject: What does this statement yield? |
|
|
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;
}
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Fri Jul 29, 2005 5:41 am Post subject: Re: What does this statement yield? |
|
|
* Frank:
| Quote: | 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?
|
|
| Back to top |
|
 |
Frank Guest
|
Posted: Fri Jul 29, 2005 6:30 am Post subject: Re: What does this statement yield? |
|
|
"Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote
| Quote: | * 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.
|
|
| Back to top |
|
 |
|