1 /* TomsFastMath, a fast ISO C bignum library.
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
6 * This project is public domain and free for all purposes.
8 * Tom St Denis, tomstdenis@gmail.com
10 #include <tfm_private.h>
12 int fp_read_radix(fp_int *a, const char *str, int radix)
17 /* set the integer to the default of zero */
20 /* make sure the radix is ok */
21 if (radix < 2 || radix > 64) {
25 /* if the leading digit is a
26 * minus set the sign to negative.
35 /* process each digit of the string */
37 /* if the radix < 36 the conversion is case insensitive
38 * this allows numbers like 1AB and 1ab to represent the same value
41 ch = (char) ((radix <= 36) ? toupper ((int)*str) : *str);
42 for (y = 0; y < 64; y++) {
43 if (ch == fp_s_rmap[y]) {
48 /* if the char was found in the map
49 * and is less than the given radix add it
50 * to the number, otherwise exit the loop.
53 fp_mul_d (a, (fp_digit) radix, a);
54 fp_add_d (a, (fp_digit) y, a);
61 /* set the sign only if a != 0 */
62 if (fp_iszero(a) != FP_YES) {