What is | and << means?

Sorry if this is a general question, but I don’t know what he called, so it’s hard for me to find it.

How it works:

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

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

If I look at the typedef for UIViewAutoresizing, it looks like this:

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

So how does one variable store more than one value like this?

+5
source share
2 answers

"|" is a striking "or".

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

00100 << 1 = 01000

Read the wiki , you are interested in "or" operations and shifts.

+6

C.

| : 0001 | 0010 = 0011.

<< : 0001 < 1 = 0010.

.

+3

All Articles