fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. int readbit(FILE *f)
  5. {
  6. static int buffer;
  7. static int n = 0;
  8.  
  9. if (n == 0) {
  10. buffer = fgetc(f);
  11. if (buffer == EOF) {
  12. return EOF;
  13. }
  14. n = 8;
  15. }
  16. return (buffer >> --n) & 1;
  17. }
  18.  
  19. int main(void)
  20. {
  21. for (int i = 0, bit; (bit = readbit(stdin)) != EOF; ++i) {
  22. printf("%d%c", bit, ((i + 1) % 8 == 0)*' ');
  23. }
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5476KB
stdin
 a0
stdout
00100000 01100001 00110000