共用体を用いてビット単位で操作できる1バイトの仮想レジスタを定義ぢ、「2進数8桁の文字列」で入力した2つの数値データの、加算、減算、論理積、論理和、排他的論理和、否定の演算結果を2進数8桁で出力するプログラムを作成せよ。

という課題がでて以下の様なソースを書いたのですが、エラー処理の方法がよくわかりません。やりたいことは０と1以外の数を入力したら
エラーと表示、8桁でなければエラーと表示してもらいたいです。それと先生に出力の書き方が少しおかしいと言われたのですが、このソースで
動いてしまいました。プログラミングの授業的になにかまずいことでもあるのでしょうか？それも出来れば教えてもらいたいです。


#include<stdio.h>

typedef union{
  char data;
  struct{
    unsigned int bit1 :1;
    unsigned int bit2 :1;
    unsigned int bit3 :1;
    unsigned int bit4 :1;
    unsigned int bit5 :1;
    unsigned int bit6 :1;
    unsigned int bit7 :1;
    unsigned int bit8 :1;
  }BIT;
}DATA;

int main(void){
  DATA a,b,sum,sub,AND,OR,aNOT,bNOT,XOR;
  char ahako[9],bhako[9];
  int i;

  scanf("%s",ahako);
  scanf("%s",bhako);
 
  a.BIT.bit8 = ahako[0]-48;
  a.BIT.bit7 = ahako[1]-48;
  a.BIT.bit6 = ahako[2]-48;
  a.BIT.bit5 = ahako[3]-48;
  a.BIT.bit4 = ahako[4]-48;
  a.BIT.bit3 = ahako[5]-48;
  a.BIT.bit2 = ahako[6]-48;
  a.BIT.bit1 = ahako[7]-48;
 
  b.BIT.bit8 = bhako[0]-48;
  b.BIT.bit7 = bhako[1]-48;
  b.BIT.bit6 = bhako[2]-48;
  b.BIT.bit5 = bhako[3]-48;
  b.BIT.bit4 = bhako[4]-48;
  b.BIT.bit3 = bhako[5]-48;
  b.BIT.bit2 = bhako[6]-48;
  b.BIT.bit1 = bhako[7]-48;

 sum.data = a.data + b.data;
  sub.data = a.data - b.data;
  AND.data = a.data & b.data;
  OR.data = a.data | b.data;
  aNOT.data = ~a.data;
  bNOT.data = ~b.data;
  XOR.data = a.data ^ b.data;
 
  printf("和 %d%d%d%d%d%d%d%d\n",sum.BIT.bit8,sum.BIT.bit7,sum.BIT.bit6,sum.BIT.bit5,sum.BIT.bit4,sum.BIT.bit3,sum.BIT.bit2,sum.BIT.bit1);
 
  printf("差 %d%d%d%d%d%d%d%d\n",sub.BIT.bit8,sub.BIT.bit7,sub.BIT.bit6,sub.BIT.bit5,sub.BIT.bit4,sub.BIT.bit3,sub.BIT.bit2,sub.BIT.bit1);
 
  printf("AND %d%d%d%d%d%d%d%d\n",AND.BIT.bit8,AND.BIT.bit7,AND.BIT.bit6,AND.BIT.bit5,AND.BIT.bit4,AND.BIT.bit3,AND.BIT.bit2,AND.BIT.bit1);
 
  printf("OR %d%d%d%d%d%d%d%d\n",OR.BIT.bit8,OR.BIT.bit7,OR.BIT.bit6,OR.BIT.bit5,OR.BIT.bit4,OR.BIT.bit3,OR.BIT.bit2,OR.BIT.bit1);
 
  printf("ANOT %d%d%d%d%d%d%d%d\n",aNOT.BIT.bit8,aNOT.BIT.bit7,aNOT.BIT.bit6,aNOT.BIT.bit5,aNOT.BIT.bit4,aNOT.BIT.bit3,aNOT.BIT.bit2,aNOT.BIT.bit1);
 
printf("BNOT %d%d%d%d%d%d%d%d\n",bNOT.BIT.bit8,bNOT.BIT.bit7,bNOT.BIT.bit6,bNOT.BIT.bit5,bNOT.BIT.bit4,bNOT.BIT.bit3,bNOT.BIT.bit2,bNOT.BIT.bit1);

printf("XOR %d%d%d%d%d%d%d%d\n",XOR.BIT.bit8,XOR.BIT.bit7,XOR.BIT.bit6,XOR.BIT.bit5,XOR.BIT.bit4,XOR.BIT.bit3,XOR.BIT.bit2,XOR.BIT.bit1);

return 0 ;
}

