Is there a built-in function to reverse bit order

后端 未结 8 1364
情书的邮戳
情书的邮戳 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:10

    10 years later. But I hope this helps someone. I did a reverse operation like this:

    byte Reverse(byte value)
    {
        byte reverse = 0;
        for (int bit = 0; bit < 8; bit++)
        {
            reverse <<= 1;
            reverse |= (byte)(value & 1);
            value >>= 1;
        }
    
        return reverse;
    }
    

提交回复
热议问题