How to efficiently de-interleave bits (inverse Morton)

后端 未结 5 1077
情歌与酒
情歌与酒 2020-12-05 03:15

This question: How to de-interleave bits (UnMortonizing?) has a good answer for extracting one of the two halves of a Morton number (just the odd bits), but I need a solutio

5条回答
  •  日久生厌
    2020-12-05 03:41

    If your processor handles 64 bit ints efficiently, you could combine the operations...

    int64 w = (z &0xAAAAAAAA)<<31 | (z &0x55555555 )
    w = (w | (w >> 1)) & 0x3333333333333333;
    w = (w | (w >> 2)) & 0x0F0F0F0F0F0F0F0F; 
    ...
    

提交回复
热议问题