Function Repository Resource:

HexConvert

Source Notebook

Convert hexadecimal strings to integers and vice versa

Contributed by: Daniel de Souza Carvalho

ResourceFunction["HexConvert"][str]

converts the String form str of a hexadecimal value to an Integer.

ResourceFunction["HexConvert"][int]

converts the Integer int to a hexadecimal String.

Examples

Basic Examples (2) 

Convert a hexadecimal String to an Integer:

In[1]:=
ResourceFunction["HexConvert"]["FF"]
Out[1]=

Convert an Integer to a hexadecimal String:

In[2]:=
ResourceFunction["HexConvert"][255]
Out[2]=

Scope (2) 

Compute the Unix time:

In[3]:=
time = UnixTime[]
Out[3]=

Convert it to hexadecimal:

In[4]:=
ResourceFunction["HexConvert"][time]
Out[4]=

A second call returns the original value:

In[5]:=
ResourceFunction["HexConvert"][ResourceFunction["HexConvert"][time]]
Out[5]=

Convert an Integer created as a hash code:

In[6]:=
ResourceFunction["HexConvert"][Hash["This is the message", "MD5"]]
Out[6]=

It is the same result as using the "HexString" parameter for Hash:

In[7]:=
Hash["This is the message", "MD5", "HexString"]
Out[7]=

Publisher

Daniel de Souza Carvalho

Version History

  • 1.0.0 – 27 April 2020

License Information