/*Moneer < length; i++) { rightSum = rightSum

/*Moneer Marouf * 333 David S. * @version 1.0 */#include #include #include #include //prototypesvoid calculations();double binaryConversion(char str);void doubleConversion(double num);int main(int argc, const char * argv) { setvbuf(stdout, NULL, _IONBF, 0); while (1) { calculations(); } return 0;}/* * This method is where the calculations for binary occur. */void calculations(){ double bi1, bi2; double biTotal = 0.0; char operator; int count = 0; char *tok3; char *space; char *line = malloc (100); printf(“Enter an expression using binary numbers or Q to quit: “); fgets (line, 100, stdin); // scanf(“%lf %c %lf”, &bi1, &operator, &bi2);   if ((strlen(line)>0) && (linestrlen (line) – 1 == ‘
‘))         linestrlen (line) – 1 = ‘’; space = strtok(line, ” “); while(space != NULL) { tokcount++ = space; space = strtok(NULL, ” “); } bi1 = binaryConversion(tok0); operator = *tok1; bi2 = binaryConversion(tok2); if (operator == ‘+’) {         biTotal = bi1 + bi2;     } else if (operator == ‘-‘ && bi1 > bi2) {         biTotal = bi1 – bi2;     }else if (operator == “-” && bi1 <= bi2){     biTotal = 0.00;     } else if (operator == '/') {         biTotal = bi1 / bi2;     } else if (operator == '*') {         biTotal = bi1 * bi2;     } printf(" = ",  operator);     doubleConversion(biTotal);          free(line);     }/* * This method converts a binary to a double. */double binaryConversion(char str){ //char nums48; int i, x = 0, z = 0; int index = 0; double numTotal = 0.0; int length = (int) strlen(str); //int leftDec48,rightDec48; int storeLeft, storeRight, leftSum = 0; double rightSum = 0.0; double p = 0.0; //power to mult by for (i = 0; i < length; i++) {         if (stri == '.') {             index = i;         }     } storeLeft = x; storeRight = z; // 48 is 0 in ASCII     for (i = index - 1; i >= 0; i–) {         leftSum = leftSum + ((stri – 48) * pow(2, p++));     }     p = 0.5;         for (i = index + 1; i < length; i++) {         rightSum = rightSum + ((stri - 48) * p);         p = p / 2;     }     numTotal  =  leftSum + rightSum;     return numTotal; }/* * This method converts a double to a representation of its binary equivalent. */void doubleConversion(double conversion) { int x; //count int i;    double p = 0.0;  // power     double ogNum = conversion;    double z;       while ((pow(2, p)) < conversion) {        p++;    }    x = p;    p = (pow(2, p)/2);    z = p;          for (i = 0; i < x; i++) {    //prints our 1's        if ((conversion - z) >= 0) {            printf(“1”);            conversion = conversion – z;            z = z / 2;        //prints our 0’s        } else {            printf(“0”);            z = z / 2;        }    }    printf(“.”);    int count = 0;    double dNum;    double decPower = 0.5;    // gives us the remainder    dNum = fmod(ogNum, 1.0);    if (count < 15) {    while (dNum != 0) {      count++;        if ((dNum - decPower) >= 0) {            printf(“1”);            dNum = dNum – decPower;            decPower = decPower / 2;        } else {            printf(“0″);            decPower = decPower / 2;        }    } }        printf(”

“);}