开发者

Random C/Objective-C questions

开发者 https://www.devze.com 2023-01-18 12:40 出处:网络
I have come across a few lines of coding I do not understand, and would be grateful for clarification:开发者_如何学Python

I have come across a few lines of coding I do not understand, and would be grateful for clarification:开发者_如何学Python

  1. if(!(counter&7))
  2. ds->direction = ts->direction;


  1. if counter is a multiple of 8

  2. set the direction element of *ds equal to the direction 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

  1. if (!(counter & 7))
  2. if ((!(counter & 7)) != 0)
  3. if ((counter & 7) == 0)
  4. if the lower 3 bits of counter are zero (or if counter is a multiple of 8)

2) same as

  1. (*ds).direction = (*ts).direction;
  2. set direction of ds (must be of a struct type) to direction of ts
0

精彩评论

暂无评论...
验证码 换一张
取 消