位运算的符号:~
|
&
^
<<
>>
分别代表的是按位取反,按位或,按位与,按位异或,左移,右移
- 按位取反操作
1 0 0 1 0
0 1 1 0 1
- | 按位或操作,只有有一个为1,这个结果就为1
1 0 0 1 0
0 0 0 1 0
1 0 0 1 0
- & 按位与操作,只有两个数都为1时,才是1
1 0 0 1 0
0 0 0 1 0
0 0 0 1 0
- ^按位异或操作,不相同时候为1,相同时候为0
1 0 0 1 0
0 0 0 1 0
1 0 0 0 0
在oc中的代码
UIView *view = [[UIView alloc] initWithFrame:viewFrame];
[view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[view setBackgroundColor:[UIColor whiteColor]];
[self setView:view];
意思是,自动调整自己的宽度,保证与superView左边和右边的距离不变。自动调整自己的高度,保证与superView顶部和底部的距离不变。查看autoresizingMask的类型,其实是NSUInteger 如下
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
左移运算符
公式 x << 3 就是把x的各二进位左移3位
1<<1 实际就是 0001 << 1 = 0010 转成十进制后就是 2
1<<4 实际就是 0001 << 4 = 10000 转成十进制后就是 16
如果把16进制转为10
1 0 0 0 0
2^4 2^3 2^2 2^1 2^0
网友评论