5

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?

3
  • 4
    uint32_t is a name for an unsigned 32-bit integer type. 0x1 << 0 is 1 shifted left zero times, which is kind of silly by itself but most likely there is a 0x1 << 1 on the next line down and more beyond that. This assigns bit positions to the constants in that group.
    – Hot Licks
    Nov 26, 2013 at 12:35
  • (This is a very common pattern in C-based languages.)
    – Hot Licks
    Nov 26, 2013 at 12:52
  • stackoverflow.com/questions/13362084/…
    – Retro
    Nov 26, 2013 at 12:53

1 Answer 1

8

<< 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
1
  • I think ive got the hang of it now, thanks for the explanation :)
    – Arbitur
    Nov 26, 2013 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.