Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does | and << mean?

Tags:

objective-c

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:

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?

like image 575
oskob Avatar asked Feb 03 '11 11:02

oskob


1 Answers

"|" 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.

like image 153
Vladimir Ivanov Avatar answered Oct 03 '22 07:10

Vladimir Ivanov