What's value of 1<<1? how to calculate it?
本问题已经有最佳答案,请猛点这里访问。
有人能告诉我如何计算
1 2 3 4 5 6 | kSCNetworkReachabilityFlagsTransientConnection = 1<<0, kSCNetworkReachabilityFlagsReachable = 1<<1, kSCNetworkReachabilityFlagsConnectionRequired = 1<<2, kSCNetworkReachabilityFlagsConnectionOnTraffic = 1<<3, kSCNetworkReachabilityFlagsInterventionRequired = 1<<4, kSCNetworkReachabilityFlagsConnectionOnDemand = 1<<5, // |
这只是一个有点移位的操作。
1 2 3 4 5 | 1 << 0 = 1 1 << 1 = 2 1 << 2 = 4 1 << 3 = 8 etc... |
或在二进制视图中
1 2 3 | 00000001 << 1 = 00000010 00000001 << 2 = 00000100 00000001 << 3 = 00001000 |
"<<"表示左移位(二进制数)。所以1<
1 2 3 | 1<<0 = 1b 1<<1 = 10 1<<2 = 100 |
这是左移位接线员。
所有的钻头都向左移动了一个位置。结果是移位值的*2。
喜欢
1<<3将是1*2*2*2=8,移位3位,所以3次*2