showbits.c 533 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. /*
  5. * cc showbits.c -O3 -o sb
  6. */
  7. static void showbits(const uint32_t data)
  8. {
  9. uint32_t mask = 1<<31;
  10. size_t i = 31;
  11. for(; i;)
  12. printf("%02zu\u00B7", i--);
  13. puts("00");
  14. for(; mask; mask >>= 1 ) {
  15. printf("%s", (uint32_t)(data & mask) ? "\u2731\u2731" : "__");
  16. if (mask != 1)
  17. printf("\u205E");
  18. }
  19. puts("");
  20. }
  21. int main(int argc, char *argv[])
  22. {
  23. if (argc < 2)
  24. exit(EXIT_FAILURE);
  25. showbits(strtol(argv[1], NULL, 16));
  26. puts("");
  27. return EXIT_SUCCESS;
  28. }