Reputation: 1828
please someone explain to me some strange Swift syntax, I've tried to google it and checked Apple's docs but haven't find any example of using it.
So here is some code from a tutorial I'm trying to follow.
let FSBoundaryCategory: UInt32 = 1 << 0
I don't get what is the meaning of <<
.
It's definitely not a twice less than or so :) Please, explain, I'm very curious about it :)
Upvotes: 0
Views: 2568
Reputation: 6612
This is the "bit shifting" operator.
Maybe the apple documentation ( goo.gl/DXVBJD ) is too complicated to start with.
But, the basic idea is that the initial bit (1) representation is : 00000000000000000000000000000001
If you shift it from one bit, using either this syntax 0b10 or this one 0x1 << 1 the bit goes one place to the left : 00000000000000000000000000000010. You can shift it from two place using 0b100 or 0x1 << 2 and so on...
Here is a table I've made for another question, that might help you too : http://goo.gl/7D8EGY
Upvotes: 6
Reputation: 53
Existing bits are moved to the left by the requested number of places. In this case 0 means it won't change, so it does nothing.
Upvotes: 1
Reputation: 7549
It's a left bitwise shift operator. You can read more about it at Apple Docs here
Upvotes: 2