diff --git a/src/bin/fp_read_radix.c b/src/bin/fp_read_radix.c index 02d0d0f..2c35e82 100644 --- a/src/bin/fp_read_radix.c +++ b/src/bin/fp_read_radix.c @@ -1,10 +1,10 @@ /* TomsFastMath, a fast ISO C bignum library. - * + * * This project is meant to fill in where LibTomMath * falls short. That is speed ;-) * * This project is public domain and free for all purposes. - * + * * Tom St Denis, tomstdenis@gmail.com */ #include @@ -14,6 +14,9 @@ int fp_read_radix(fp_int *a, char *str, int radix) int y, neg; char ch; + /* set the integer to the default of zero */ + fp_zero (a); + /* make sure the radix is ok */ if (radix < 2 || radix > 64) { return FP_VAL; @@ -29,16 +32,13 @@ int fp_read_radix(fp_int *a, char *str, int radix) neg = FP_ZPOS; } - /* set the integer to the default of zero */ - fp_zero (a); - /* process each digit of the string */ while (*str) { /* if the radix < 36 the conversion is case insensitive * this allows numbers like 1AB and 1ab to represent the same value * [e.g. in hex] */ - ch = (char) ((radix < 36) ? toupper ((int)*str) : *str); + ch = (char) ((radix <= 36) ? toupper ((int)*str) : *str); for (y = 0; y < 64; y++) { if (ch == fp_s_rmap[y]) { break;