/***************************** * text2bin.c * Converts stdin stream of chars * to ASCII codes, to binary representation * of the codes as text '0's and '1's, * one char per line of text. Suitable for * readmemb() input. Produces files the same * size the the kb_device's data[]. If the * input chars are less than the size of data[], * vvp will complain, but simulation will go * ahead regardless. *****************************/ #include #define KB_DATA_SIZE 256 char c; char l[8]; int cnt,i; int main(void){ while( (c = getchar()) != EOF){ cnt++; for(i=0;i<8;i++){ if((c%2)==0){ l[i] = '0'; } else { l[i] = '1'; } c = c >> 1; } for(i=7;i>=0;i--){ printf("%c", l[i]); } printf("\n"); } printf("00000000\n"); }