| 316 | */ |
| 317 | |
| 318 | static int _valid(char ch, int base) |
| 319 | { |
| 320 | char end = (base > 9) ? '9' : '0' + (base - 1); |
| 321 | |
| 322 | /* all bases will be some subset of the 0-9 range */ |
| 323 | |
| 324 | if (ch >= '0' && ch <= end) |
| 325 | return 1; |
| 326 | |
| 327 | /* Bases > 11 will also have to match in the a-z range */ |
| 328 | |
| 329 | if (base > 11) { |
| 330 | if (tolower(ch) >= 'a' && |
| 331 | tolower(ch) <= 'a' + (base - 11)) |
| 332 | return 1; |
| 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | /* Return the "value" of the character in the given base */ |
| 339 |