Code:// input ASCII into input array // check ASCII numeric range (0x30-0x39 & 0x2E) here, and subtract 0x30 for all but 0x2E // rotate input array left until the decimal point is aligned with twopi array unsigned int input = 100; // 2:45am cheat unsigned char twopi[19] = { 0x00,0x00,0x00,0x06,0x02,0x08,0x03,0x01,0x08,0x05,0x03,0x00,0x07,0x01,0x07,0x09,0x05,0x09,0x00 }; unsigned char otput[19] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; int adcnt = 0; // counter unsigned char dgcnt = 0; // digit index unsigned char carry = 0; // carry digit while (adcnt < input) { // multiply through addition dgcnt = 17; carry = 0; while (dgcnt > 0) { // cycle the digits otput[dgcnt] = otput[dgcnt] + twopi[dgcnt] + carry; carry = 0;// add digit if (otput[dgcnt] > 9) { otput[dgcnt] = otput[dgcnt] - 10; carry = 1; } // carry digit dgcnt--; } // dgcnt if (carry != 0) { otput[dgcnt] = otput[dgcnt] + 1; } adcnt++; } // adcnt twopi[18] = 0x00; // terminate string printf("%d%d%d%d.%d%d%d%d%d%d",otput[0],otput[1],otput[2],otput[3],otput[4],otput[5],otput[6],otput[7],otput[8],otput[9]); // answer: 1884.9555921538758




Bookmarks