fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. typedef enum {
  5. ONE = 0x1,
  6. TWO = 0x2,
  7. THREE = 0x4,
  8. FOUR = 0x8,
  9. } options;
  10.  
  11. static const char *byte_to_binary (int x)
  12. {
  13. int z;
  14. static char b[9];
  15. b[0] = '\0';
  16.  
  17. for (z = 256; z > 0; z >>= 1)
  18. {
  19. strcat(b, ((x & z) == z) ? "1" : "0");
  20. }
  21.  
  22. return b;
  23. }
  24.  
  25. int main(int argc, char *argv[])
  26. {
  27. options o = 0;
  28. printf( "%s\n", byte_to_binary(o));
  29. o |= ONE;
  30. printf( "%s\n", byte_to_binary(o));
  31. o |= TWO;
  32. printf( "%s\n", byte_to_binary(o));
  33. o |= THREE;
  34. printf( "%s\n", byte_to_binary(o));
  35. o |= FOUR;
  36. printf( "%s\n", byte_to_binary(o));
  37. o &= ~FOUR;
  38. printf( "%s\n", byte_to_binary(o));
  39. o &= ~THREE;
  40. printf( "%s\n", byte_to_binary(o));
  41. o &= ~TWO;
  42. printf( "%s\n", byte_to_binary(o));
  43. o &= ~ONE;
  44. printf( "%s\n", byte_to_binary(o));
  45.  
  46. return 0;
  47. }
Runtime error #stdin #stdout 0.01s 1904KB
stdin
Standard input is empty
stdout
Standard output is empty