• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Unique ID

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

22 replies to this topic

### #21ultramailman  Prime Members

Posted 26 March 2013 - 07:52 PM

Well the solution is to mask out the bits you don't want before you do the shift... looks like your x, y are 8 bits and n is 16 bits so do

int32_t id = (n & 0xffff) | ((cell_x & 0xff) << 16) | ((cell_y & 0xff) << 24)

EDIT: Missed an effing eff

Ahhh would that work? By masking them out, the signedness of the three fields would be lost, wouldn't it? I do intend for them to be signed numbers.

For now I am using this:
// cast to unsigned
uint32_t n = uid.n, cell_x = uid.cell_x, cell_y = uid.cell_y;
uint32_t id = n | (cell_x << 16) | (cell_y << 24);

I am fine with storing the id as unsigned, as long as the bits of the three fields don't get changed by the casting.

Posted 26 March 2013 - 07:57 PM

It's not going to work for signed numbers since negative numbers are all 1s in the most significant bits.

If you cast them to signed char or signed short when you extract them it will be ok though.

Try it anyway... the wonders of printf or cout will show you what is going on...

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #23ultramailman  Prime Members

Posted 26 March 2013 - 08:40 PM

Haha thanks, I didn't think of printing. You are right, masking does the job.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.