Can you give an example how I would do it by using <<=, I thought that was a bad idea, because for example an actual value of one of the integers, might be smaller then the number of reserved bits. Doing it like I do above/ now, makes sure the bits are always on the same starting place.

The dist to cam conv(erted) is actually also an int (converted to a range 0 - 255), so it will fit into 8 bits.

As I understand correctly it sorts from right to left, because most right bits are the material group, then material etc.

The only thing I don't understand yet is why it now sorts first on distance and then on inst (because the bits are the other way around).

Update: it doesn't, I just had a bad example. I'll play around switching inst and dist and see what happens