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?

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
Arbitur
  • 38,684
  • 22
  • 91
  • 128
  • 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 '13 at 12:35
  • (This is a very common pattern in C-based languages.) – Hot Licks Nov 26 '13 at 12:52
  • http://stackoverflow.com/questions/13362084/difference-between-uint32-and-uint32-t – Retro Nov 26 '13 at 12:53

1 Answers1

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
Community
  • 1
  • 1
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124