I have BASIC logical question about the following code snippet:
1 uint64_t RMTileKey(RMTile tile)
2 {
3 uint64_t zoom = (uint64_t) tile.zoom & 0xFFLL; // 8bits, 256 levels
4 uint64_t x = (uint64_t) tile.x & 0xFFFFFFFLL; // 28 bits
5 uint64_t y = (uint64_t) tile.y & 0xFFFFFFFLL; // 28 bits
6
7 uint64_t key = (zoom << 56) | (x << 28) | (y << 0);
8
9 return key;
10 }
The return value key is an unsigned integer.
I am very confused now, because i dont understand what is happening in line 3(4,5). The operator & does what with my uint64_t. I guess it is converting to a hex-value ?
And then in line 7 i shift from bit 0 to 27 (28 to 56 …) and merge theses hex-based numbers?
line 3:
zoomhas all the bits except 0 to 7 clear:0000...000zzzzzzzz8 bitsline 4:
xhas all the bits except 0 to 27 clear:0000...000xxxx...xxxx; 28 bitsline 5:
yhas all the bits except 0 to 27 clear:0000...000yyyy...yyyy; 28 bitsline 7: the bits are rearranged to make a single 64-bit value:
,--------------------- bit 56 / ,----------- bit 28 / / ,- bit 0 zzzzzzzzxxxx...xxxxyyyy...yyyy zoom<<56 x<<28 y<<0