Szabolcs
Szabolcs

Reputation: 25703

Is there a builtin Mathematica function to read hexadecimals in 0-9,a-f format?

Is there a builtin Mathematica function that parses strings representing numbers in hexadecimal form, e.g. "89ab"?

I could use

FromDigits[
 ToExpression[Characters["89ab"] /. 
       Thread[CharacterRange["a", "f"] -> Range[10, 15]]], 
 16
]

or even

ToExpression["16^^" <> "89ab"]

but I'm sure there must be a more robust builtin function with error checking that I just cannot find.

Upvotes: 3

Views: 116

Answers (1)

kennytm
kennytm

Reputation: 523214

FromDigits[] can already work with strings.

In[7]:= FromDigits["89ab", 16]

Out[7]= 35243

Upvotes: 8

Related Questions