开发者

What does | and << mean?

Sorry if this is a common question but I don't know what it's called so I'm having trouble searching for it.

How does this work:

开发者_C百科
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

I understand that it means that the view gets both flexible width and height, but how does it store two variables like that?

If i look at the typedef for UIViewAutoresizing it looks like:

enum {
    UIViewAutoresizingNone                 = 0,
    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
    UIViewAutoresizingFlexibleWidth        = 1 << 1,
...

So, how can one variable store more than one value like this?


"|" is a bitwise 'or'.

"<<" is also a bitwise operation shifting. it moves all the bits to the left:

00100 << 1 = 01000

Read the wiki, you're interested in "or" and shift operations.


These are C bit level operators.

| is binary or: 0001 | 0010 = 0011.

<< is a bit shift: 0001 << 1 = 0010.

They are used for bitmasks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜