Get a hexadecimal representation of an integer as a string in Mathematica

Is there a built-in way in Mathematica to get the hexadecimal representation of a positive integer as a string (using letters of the alphabet as higher digits)? I am currently using my own implementation as

toHexString[n_Integer] := StringJoin[ ToString /@ (IntegerDigits[n, 16] /. Thread[Range[10, 15] -> CharacterRange["A", "F"]]) ] 
+7
source share
1 answer
 In[254]:= IntegerString[{16, 34, 110, 5676767}, 16] Out[254]= {"10", "22", "6e", "569edf"} 

or, if you don't like standard lowercase letters as a result:

 In[255]:= ToUpperCase[IntegerString[{16, 34, 110, 5676767}, 16]] Out[255]= {"10", "22", "6E", "569EDF"} 

Please note that IntegerString has an optional third argument, which is very useful for generating a series of file names sorting in the correct order when sorting alphabetically:

 In[256]:= Table["filename" <> IntegerString[i, 10, 4] <> ".jpg", {i, 1, 7}] Out[256]= {"filename0001.jpg", "filename0002.jpg", "filename0003.jpg", "filename0004.jpg", "filename0005.jpg", "filename0006.jpg", "filename0007.jpg"} 
+15
source

All Articles