MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: converting hex strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27456] Re: converting hex strings
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 25 Feb 2001 20:56:05 -0500 (EST)
  • References: <97a7b2$aks@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Maarten,
ToExpression["16^^"<>#]&/@{"01a0","ffe","0080"}

        {416,4094,128}

You have one f too many.
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

<maarten.vanderburgt at icos.be> wrote in message
news:97a7b2$aks at smc.vnet.net...
> Hallo,
>
> I have a list of hexadecimal strings (read from a hex string text file):
> e.g. {"01a0", "fffe", "0080"} representing integers.
> How can I convert such a list to integers so that I get {416, 4094, 128}?
> I cannot make a function using something like
>
> hextoint = 16^^#&
>
> or
>
> hextoin = 16^^ToExpression[#]&
>
> I get errors like below:
>
> In[44]:= hexstr = "a1b0"
>          t = ToExpression[hexstr];
>          16^^t
> General::"digit": "Digit at position \!\(1\) in \!\(\"t\"\) is too large
to
> \
> be used in base \!\(16\)."
>
> Where does this error come from?
>
> While this works ok:
> In[43]:= 16^^a1b0
> Out[43]= 41392
>
> The ToExpression[ ] also would give problems: ToExpression["01a0"] returns
> 0.
>
> Has anyone done anything along these lines?
>
> How would I have to convert a hex list representing floats (IEEE floating
> point standard)?, e.g. {"42c8000", "3dfcd35b", "bf80000"} which should
> convert to {100.0, 0.12345, -1.0} in a decimal notation.
>
> Thanks for your help
>
> Maarten
>
> -------------------------------------------
> Maarten van der Burgt
>
> Icos Vision Systems
> Esperantolaan 9
> B-3001 Leuven
> Belgium
> -------------------------------------------
>
>
>




  • Prev by Date: Re: converting hex strings
  • Next by Date: Re: Integration problem
  • Previous by thread: Re: converting hex strings
  • Next by thread: Re: Re: converting hex strings