Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain uint32_t and 0x1 << 0 in Apple SpriteKit sample code

I found a couple of lines in apples sample codes for SpriteKit

static const uint32_t missileCategory  =  0x1 << 0;

I know what static const is but what is an uint32_t and what does 0x1 << 0 mean? is it some sort of hex?

like image 764
Arbitur Avatar asked Nov 26 '13 12:11

Arbitur


1 Answers

<< is bitwise left shift (multiply by 2) operator.

<< 0 is the same as *1

So equivalent statement would be:

static const uint32_t missileCategory  =  0x1;

I wrote more on this here.

For example:

0x1 << 4 would return 0x10.

Looking at it binary:

00000001 << 4 = 00010000

Decimaly speaking this would mean 1 * 2 * 2 * 2 * 2 or 1 * 2^4

And since this is uint32_t value it would actualy be

0x00000010
like image 177
Rok Jarc Avatar answered Oct 14 '22 15:10

Rok Jarc