Advertisement
BinYamin

Decodin asciied binary

Sep 22nd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. /*
  2.  *  If you have nerdy friends who like to talk in binary encoded ASCII
  3.  *  and if you are not a digital machine
  4.  *  or you can't read the ascii values and figure out whats written
  5.  *  all you need to do is save the strings of 1s and 0s in fin.txt file
  6.  *  in default directory and run this code. :)
  7.  *
  8.  */
  9.  
  10. #include<stdio.h>
  11.  
  12. int main()
  13. {
  14.   int i,j,k;
  15.   char c, d;
  16.  
  17.   FILE *in;
  18.   in = fopen("fin.txt","r");
  19.   if (in==NULL) {
  20.     printf("bye");
  21.     return 1;
  22.   } else {
  23.     printf("ok");
  24.   }
  25.  
  26.     while( 1) {
  27.     j=d=0;
  28.     do{
  29.         c= fgetc(in);
  30.         if(c=='1'){
  31.         d<<=1;
  32.         d = d|1;
  33.         j++;
  34.         } else if(c=='0') {
  35.         d<<=1;
  36.         j++;
  37.         } else if (c==EOF) {
  38.         return 0;
  39.         } else {
  40.         printf("%c",c);
  41.         }
  42.     }while(j<8);
  43.     printf("%c", d);
  44.     }
  45.    return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement