發現如下代碼
const ( defaultMaxMemory = 32 << 20 // 32 MB)這個32M真是有逼格的寫法,首先簡單介紹一下<<左移以為相當于乘以2,左移20相當于乘以2的20次冪
這個有個你需要裝13的技能,就是背過常用的2的冪表 7 128
8 256
10 1024 1K
16 65536 64K
20 1048576 1MB
30 1073741824 1GB
40 1099511627776 1TB
最起碼要知道1K 1M 1G 1T 各是2的多少次冪
按位& 與我們寫判斷條件的&&類似 都為true才為true,而這里是都為1才為1 按位| 與我們寫判斷條件的||類似 只要一個為true結果為true,而這里是只要一個為1結果為1 異或^ 不一樣則為1,否則為0 取反~ 0變1,1變0 左移<< 用來將一個數的各個二進制位全部左移若干位,所以相當于乘以2,但是左移比乘法快的多(參考C程序設計第三版 譚浩強 323頁) 右移>> 用來將一個數的各個二進制位全部右移若干位,無符號數左邊高位補0,有符號數左邊高位補0還是1取決計算機系統
清零取數要用與,某位置一可用或 若要取反和交換,輕輕松松用異或
1、位掩碼(BitMask)在iOS中用在NS_OPTIONS。 在UIView.h中可以看到有個@PRoperty(nonatomic) UIViewAutoresizing autoresizingMask; 而UIViewAutoresizing的定義如下
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};再看上面UIViewAnimationTransition的定義
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { UIViewAnimationTransitionNone, UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown,};前者是位掩碼實現,可以自由組合,例如
autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin代表右上自動調整邊距。
取消頂部調整
autoresizingMask = autoresizingMask &~ UIViewAutoresizingFlexibleTopMargin判斷右邊是否自動調整
if (autoresizingMask & UIViewAutoresizingFlexibleRightMargin) == UIViewAutoresizingFlexibleRightMargin2、UI設計師給的顏色16進制例如0xff0000 如何得到10進制顏色
我們通常說的RGB顏色都是24位的,也就是R、G、B分別占8位。
#define mRGBToColor(rgb) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0](rgb & 0xFF0000) 可以取到紅色其它置0 而右移16位因為一種顏色占8位,所以R要移動兩個8位即16
3、判斷奇偶 i & 1 == 1 奇數 i & 1 == 0 偶數
4、待續
新聞熱點
疑難解答