Get an array of the bit positions within a 64-bit integer

前端 未结 8 1405
囚心锁ツ
囚心锁ツ 2020-12-30 06:07

OK, it may sound a bit complicated, but this is what I\'m trying to do :

  • Take e.g. 10101010101
  • And return { 0, 2, 4, 6, 8, 10 }
8条回答
  •  春和景丽
    2020-12-30 07:09

    The fastest I can think of right now would be using a pre-generated map array of all numbers (it doesn't have to be all numbers, you can for example break the numbers in 8-bit or 16-bit parts and then concatenate the returned arrays with some proper additions to account for the actual position of the bits).

提交回复
热议问题