1 /* xtom -- convert a hexadecimal string to a MINT, and return a pointer to
4 Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Library General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16 License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
28 digit_value_in_base (c, base)
50 xtom (const char *str)
62 MINT *x = (MINT *) (*_mp_allocate_func) (sizeof (MINT));
65 /* Skip whitespace. */
77 if (digit_value_in_base (c, 16) < 0)
78 return 0; /* error if no digits */
81 str_size = strlen (str - 1);
82 s = begs = (char *) TMP_ALLOC (str_size + 1);
84 for (i = 0; i < str_size; i++)
88 int dig = digit_value_in_base (c, 16);
101 xsize = str_size / __mp_bases[16].chars_per_limb + 1;
102 x->_mp_alloc = xsize;
103 x->_mp_d = (mp_ptr) (*_mp_allocate_func) (xsize * BYTES_PER_MP_LIMB);
105 xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, 16);
106 x->_mp_size = negative ? -xsize : xsize;