<p>Is there a built in way to convert an integer in Ruby into its hexadecimal equivalent?</p>

<p>Something like the opposite of <a href="http://ruby-doc.org/core-2.0.0/String.html#method-i-to_i" rel="noreferrer"><code>String#to_i</code></a>:</p>

<pre><code>"0A".to_i(16) #=&gt;10
</code></pre>

<p>Like perhaps:</p>

<pre><code>"0A".hex #=&gt;10
</code></pre>

<p>I know how to roll my own, but it's probably more efficient to use a built in Ruby function.</p>

How about using
```
%
```
/
```
sprintf
```
:
```
```
i = 20
"%x" % i  #=> "14"
```
```