-1

Can any one tell me how to calculate value of 1<<0 and others ? I am new to iOS and it's difficult for me to understand it.

 kSCNetworkReachabilityFlagsTransientConnection = 1<<0,
  kSCNetworkReachabilityFlagsReachable      = 1<<1,
  kSCNetworkReachabilityFlagsConnectionRequired = 1<<2,
  kSCNetworkReachabilityFlagsConnectionOnTraffic    = 1<<3,
  kSCNetworkReachabilityFlagsInterventionRequired   = 1<<4,
  kSCNetworkReachabilityFlagsConnectionOnDemand = 1<<5, // 
Ajoy
  • 1,834
  • 3
  • 30
  • 55
Vishwa816
  • 321
  • 1
  • 4
  • 6

3 Answers3

7

It's just a bit-shift operation.

1 << 0 = 1
1 << 1 = 2
1 << 2 = 4
1 << 3 = 8
etc...

or in binary view

00000001 << 1 = 00000010
00000001 << 2 = 00000100
00000001 << 3 = 00001000
Marc B
  • 348,685
  • 41
  • 398
  • 480
1

This is left shift operator.

All the bits are shifted one place toward left. Resulting is *2 of the value by shifting value.

like

1<<3 will be 1*2*2*2=8, shifted 3 bits so three times *2

Anoop Vaidya
  • 45,913
  • 15
  • 108
  • 138
1

"<<" indicates left shift (in binary numbers). So 1 << n is the same as 2 to the power of n. However it is most appropriate to look at it in binary,

1<<0 = 1b
1<<1 = 10
1<<2 = 100
Udo Klein
  • 6,598
  • 1
  • 35
  • 61