User Tools

Site Tools

blog:2023-04-20_c_bit_reverse_in_a_byte



2023-04-20 C#: bit Reverse in a Byte

  • I need a bit reverse in a byte function.
  • [b7][b6][b5][b4][b3][b2][b1][b0]
  • convert into
  • [b0][b1][b2][b3][b4][b5][b6][b7]
  • Here is my solution.

Solution

  • private byte ReverseBits(byte inData)
    {
    	inData = (byte)(((inData & 0x0F) << 4) | ((inData & 0xF0) >> 4));
    	inData = (byte)(((inData & 0x33) << 2) | ((inData & 0xCC) >> 2));
    	inData = (byte)(((inData & 0x55) << 1) | ((inData & 0xAA) >> 1));
    
    	return inData;
    }

TAGS

  • 95 person(s) visited this page until now.

Permalink blog/2023-04-20_c_bit_reverse_in_a_byte.txt · Last modified: 2023/04/20 15:40 by jethro

oeffentlich