Is there a built-in function to reverse bit order

后端 未结 8 1343
情书的邮戳
情书的邮戳 2020-12-13 00:34

I\'ve come up with several manual ways of doing this, but i keep wondering if there is something built-in .NET that does this.

Basically, i want to reverse the bit o

8条回答
  •  轮回少年
    2020-12-13 01:19

    No, there isn't anything in the BCL for this.

    But, assuming you want something fast:

    • Since there are only 8 bits, it pays to unroll the loop (use 4 statements instead of the for-loop).

    • For an even faster solution, create a 256 entry lookup table.

    And you can of course wrap both methods in a function so that the usage only takes 1 statement.

    I found a page for this problem.

提交回复
热议问题