/*------+---------+---------+---------+---------+---------+--------+*\ | | | Function: toInt | | Input: base to convert by (default is 10) | | Output: int | | Purpose: This function returns the integer value of the string. | | It can be used for binary, decimal, octal, and hex. | | | \*------+---------+---------+---------+---------+---------+--------+*/ int String::toInt(int base) { int intValue = 0; if (base != 2 && base != 8 && base != 10 && base != 16) return 0; if (base == 16) toUpper(); for (int i = 0; i < length; i++) { intValue *= base; if(base == 16 && data[i] >= 'A' && data[i] <= 'F') { intValue += (data[i] - 'A' + 10); } else intValue += (data[i] - '0'); } return intValue; } /*------+---------+---------+---------+---------+---------+--------+*\ | | | Function: toFloat | | Input: void | | Output: float | | Purpose: This function returns to float value of the string. | | | \*------+---------+---------+---------+---------+---------+--------+*/ float String::toFloat() { //Local Variables int i = 0; float floatValueLeft = 0; float floatValueRight = 0; while (data[i] != '.' && data[i] != '\0') { floatValueLeft *= 10; floatValueLeft += (data[i] - '0'); i++; } if (data[i] != '\0') { i = length - 1; while (data[i] != '.') { floatValueRight /= 10; floatValueRight += (data[i] - '0'); i--; } floatValueRight /= 10; } return floatValueLeft + floatValueRight; }