Return to Snippet

Revision: 55908
at February 28, 2012 13:45 by putu


Initial Code
//Add as static field of a Class
static byte[] _RevBitsTable = 
{
	0x00,0x08,0x04,0x0C,
	0x02,0x0A,0x06,0x0E,
	0x01,0x09,0x05,0x0D,
	0x03,0x0B,0x07,0x0F              
};

//Add as method of a Class
static byte ReverseBits(byte data)
{
	byte ln = _RevBitsTable[data & 0x0F];
	byte hn = _RevBitsTable[(data >> 4) & 0x0F];
	return (byte)((ln << 4) | hn);
}

Initial URL

                                

Initial Description
Reverse bit order of a byte variable, e.g. 0000 0001 (0x01) --> 1000 000 (0x80).

Initial Title
Reverse bit order

Initial Tags

                                

Initial Language
C#