fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. int main(void) {
  5. int i;
  6. uint64_t x = 530797644;
  7.  
  8. printf("binary input as a single integer: %08lX\n", x);
  9.  
  10. printf("binary input as a sequence of integer bytes: ");
  11. for (i = 0; i < 4; ++i)
  12. printf("%02hhX", ((char *)&x)[i]);
  13. putchar('\n');
  14.  
  15. x = ((x & 0x00000000ffff0000LL) << 16) | (x & 0x000000000000ffffLL);
  16. x = ((x & 0x0000ff000000ff00LL) << 8) | ((x & 0x000000ff000000ffLL) >> 0);
  17. x = ((x & 0x000f000f000f000fLL) << 8) | ((x & 0x00f000f000f000f0LL) >> 4);
  18. x = (x + 0x3030303030303030LL) +
  19. (((x + 0x0606060606060606LL) & 0x1010101010101010LL) >> 4) * 7;
  20.  
  21. printf("hex output as a single integer: %016lX\n", x);
  22.  
  23. printf("hex output as a sequence of chars: ");
  24. for (i = 0; i < 8; ++i)
  25. putchar(((char *)&x)[i]);
  26. putchar('\n');
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
binary input as a single integer: 1FA3544C
binary input as a sequence of integer bytes: 4C54A31F
hex output as a single integer: 4631334134354334
hex output as a sequence of chars: 4C54A31F