C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What does this statement yield?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Frank
Guest





PostPosted: Fri Jul 29, 2005 5:32 am    Post subject: What does this statement yield? Reply with 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;
}



Back to top
Alf P. Steinbach
Guest





PostPosted: Fri Jul 29, 2005 5:41 am    Post subject: Re: What does this statement yield? Reply with quote



* 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





PostPosted: Fri Jul 29, 2005 6:30 am    Post subject: Re: What does this statement yield? Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.