1

If I have 11, I'd like to perform some kind of bitwise operation and get 1010.

If I have 111, 101010.

If I have 101, 100010.

Can I do this? How?

If so, is it possible to do this arbitrarily, i.e., if I wanted to interleave 8 0-bits for 8 value-bits: 11101110 01101010 -> 11101110 00000000 01101010 00000000

  • I recognize this may be better for CSE. Let me know if I should migrate. – Liam Monninger Jan 19 '22 at 06:10
  • It's not a true duplicate but you can use the same techniques as [Morton encoding](https://stackoverflow.com/q/30539347/555045) (but with only half the code) – harold Jan 19 '22 at 10:27
  • Thanks! Trying to internalize Morton encoding. While I do, would you know if it is possible to interleave an arbitrary number of 0-bits between an arbitrary number of valued bits using Morton encoding? – Liam Monninger Jan 19 '22 at 15:55
  • Yes, but some of the approaches easily allow that and some of them don't. There are also versions that interleave 3 coordinates (and can therefore be used to insert 2 zero bits between every bit) and 4 and so on. The version based on `pdep` is extremely flexible in how many zeroes it inserts and where, but limited to certain hardware. – harold Jan 19 '22 at 16:12

0 Answers0