fork download
  1. #include <stdio.h>
  2. #include <assert.h>
  3. #include <stdint.h>
  4.  
  5. inline uint16_t reverse(uint16_t v) {
  6. v = ((v >> 1) & 0x5555) | ((v & 0x5555) << 1); /* swap odd/even bits */
  7. v = ((v >> 2) & 0x3333) | ((v & 0x3333) << 2); /* swap bit pairs */
  8. v = ((v >> 4) & 0x0F0F) | ((v & 0x0F0F) << 4); /* swap nibbles */
  9. v = ((v >> 8) & 0x00FF) | ((v & 0x00FF) << 8); /* swap bytes */
  10. return v;
  11. }
  12.  
  13. main() {
  14. uint16_t gf_t = 44;
  15. printf("%hu\n", reverse(gf_t));
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
13312