1 2 3 4 5 6 7 8 9 |
Переворачивает байт. uint8_t mirror (uint8_t c) // чудесная функция { c = ((c>>1) & 0x55) | ((c<<1) & 0xAA); c = ((c>>2) & 0x33) | ((c<<2) & 0xCC); c = ((c>>4) & 0x0F) | ((c<<4) & 0xF0); return c; } |
Способ 2:
1 2 3 4 |
unsigned char ReverseBits3ops64bit(unsigned char v) { return (v * 0x0202020202ULL & 0x010884422010ULL) % 1023; } |
Также ссылки на эту тему:
https://medium.com/square-corner-blog/reversing-bits-in-c-48a772dc02d7
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489h/Cihjgdid.html