Swift – static let and "<<" meaning

<< is the left shift operator. You can better visualize it in binary:

   1        0000 0001
<< 1                ^ shift this one bit to the left
----  =     ---------
   2        0000 0010


   1        0000 0001
<< 2                ^ shift this two bits to the left
----  =     ---------
   4        0000 0100


   3        0000 0011
<< 2                ^ shift this two bits to the left
----  =     ---------
  12        0000 1100

Another property to remember is x << n = x * (2^n). The opposite of << is >> – the right shift operator.

Leave a Comment