fork download
  1. #include <stdio.h>
  2. void printBits(size_t const size, void const * const ptr)
  3. {
  4. unsigned char *b = (unsigned char*) ptr;
  5. unsigned char byte;
  6. int i, j;
  7.  
  8. for (i=size-1;i>=0;i--)
  9. {
  10. for (j=7;j>=0;j--)
  11. {
  12. byte = b[i] & (1<<j);
  13. byte >>= j;
  14. printf("%u", byte);
  15. }
  16. }
  17. puts("");
  18. }
  19.  
  20. int main(int argv, char* argc[])
  21. {
  22. int i = 23;
  23. unsigned int ui = 45;
  24. float f = 23.45f;
  25. printBits(sizeof(i), &i);
  26. printBits(sizeof(ui), &ui);
  27. printBits(sizeof(f), &f);
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
00000000000000000000000000010111
00000000000000000000000000101101
01000001101110111001100110011010