Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 359
Szabolcs Avatar asked Dec 28 '25 16:12

Szabolcs


1 Answers

FromDigits[] can already work with strings.

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

Out[7]= 35243
like image 108
kennytm Avatar answered Dec 31 '25 12:12

kennytm