Skip to content

Instantly share code, notes, and snippets.

@tailnode
Created November 26, 2014 10:45
Show Gist options
  • Save tailnode/7356579379c650c50e6a to your computer and use it in GitHub Desktop.
Save tailnode/7356579379c650c50e6a to your computer and use it in GitHub Desktop.
按二进制格式颠倒各个位顺序:0xAA(10101010) -> 0x55(0x01010101)
unsigned int revert(unsigned char data)
{
const unsigned char table[] = {0, 2, 1, 3};
unsigned int revert = (table[data >> 6]) | (table[(data & 0x30) >> 4] << 2)
| (table[(data & 0x0c) >> 2] << 4) | (table[data & 0x03] << 6);
return revert;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment