1 /* xtom -- convert a hexadecimal string to a MINT, and return a pointer to
4 Copyright 1991, 1994, 1995, 1996, 2000, 2001, 2002, 2005 Free Software
7 This file is part of the GNU MP Library.
9 The GNU MP Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
14 The GNU MP Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
28 extern const unsigned char __gmp_digit_value_tab[];
29 #define digit_value __gmp_digit_value_tab
32 xtom (const char *str)
40 MINT *x = (MINT *) (*__gmp_allocate_func) (sizeof (MINT));
43 /* Skip whitespace. */
45 c = (unsigned char) *str++;
52 c = (unsigned char) *str++;
55 if (digit_value[c] >= 16)
56 return 0; /* error if no digits */
59 str_size = strlen (str - 1);
60 s = begs = (char *) TMP_ALLOC (str_size + 1);
62 for (i = 0; i < str_size; i++)
66 int dig = digit_value[c];
74 c = (unsigned char) *str++;
79 xsize = str_size / mp_bases[16].chars_per_limb + 1;
81 x->_mp_d = (mp_ptr) (*__gmp_allocate_func) (xsize * BYTES_PER_MP_LIMB);
83 xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, 16);
84 x->_mp_size = negative ? -xsize : xsize;