fork download
  1. #include<stdio.h>
  2.  
  3. typedef union{
  4. unsigned char data;
  5. struct{
  6. unsigned char bit1 :1;
  7. unsigned char bit2 :1;
  8. unsigned char bit3 :1;
  9. unsigned char bit4 :1;
  10. unsigned char bit5 :1;
  11. unsigned char bit6 :1;
  12. unsigned char bit7 :1;
  13. unsigned char bit8 :1;
  14. }BIT;
  15. }DATA;
  16.  
  17. DATA input(void)
  18. {
  19. unsigned char hako[9];
  20. DATA d;
  21. int i;
  22.  
  23. while (1) {
  24. scanf("%8s", hako);
  25. for (i = 0; i < 8; i++) {
  26. hako[i] -= '0';
  27. if (1 < hako[i]) {
  28. break;
  29. }
  30. }
  31. if (i == 8) {
  32. d.BIT.bit8 = hako[0];
  33. d.BIT.bit7 = hako[1];
  34. d.BIT.bit6 = hako[2];
  35. d.BIT.bit5 = hako[3];
  36. d.BIT.bit4 = hako[4];
  37. d.BIT.bit3 = hako[5];
  38. d.BIT.bit2 = hako[6];
  39. d.BIT.bit1 = hako[7];
  40. break;
  41. }
  42. }
  43. return d;
  44. }
  45.  
  46. void output(char* str, DATA d)
  47. {
  48. printf("%s\t%u%u%u%u%u%u%u%u\n", str,
  49. d.BIT.bit8, d.BIT.bit7, d.BIT.bit6, d.BIT.bit5,
  50. d.BIT.bit4, d.BIT.bit3, d.BIT.bit2, d.BIT.bit1);
  51. }
  52.  
  53. int main(void){
  54. DATA a,b,sum,sub,AND,OR,aNOT,bNOT,XOR;
  55. int i;
  56.  
  57. a = input();
  58. b = input();
  59.  
  60. sum.data = a.data + b.data;
  61. sub.data = a.data - b.data;
  62. AND.data = a.data & b.data;
  63. OR.data = a.data | b.data;
  64. aNOT.data = ~a.data;
  65. bNOT.data = ~b.data;
  66. XOR.data = a.data ^ b.data;
  67.  
  68. output("和", sum);
  69. output("差", sub);
  70. output("AND", AND);
  71. output("OR", OR);
  72. output("ANOT", aNOT);
  73. output("BNOT", bNOT);
  74. output("XOR", XOR);
  75.  
  76. return 0 ;
  77. }
  78.  
Success #stdin #stdout 0.01s 1680KB
stdin
01010011
11110101
stdout
和	01001000
差	01011110
AND	01010001
OR	11110111
ANOT	10101100
BNOT	00001010
XOR	10100110