Random C/Objective-C questions
I have come across a few lines of coding I do not understand, and would be grateful for clarification:开发者_如何学Python
if(!(counter&7))
ds->direction = ts->direction;
if
counter
is a multiple of 8set the
direction
element of*ds
equal to thedirection
element of*ts
The first checks if the result of a bitwise-AND on the counter with 7 is not zero, and the latter assigns the value of the direction
member of one struct to the direction
member of another.
1) same as
if (!(counter & 7))
if ((!(counter & 7)) != 0)
if ((counter & 7) == 0)
- if the lower 3 bits of counter are zero (or if counter is a multiple of 8)
2) same as
(*ds).direction = (*ts).direction;
- set direction of
ds
(must be of a struct type) to direction ofts
精彩评论