<blockquote>
<p>y = hex(xPublicKey).rstrip(&quot;L&quot;).lstrip(&quot;0x&quot;)</p>
<p>z = hex(yPublicKey).rstrip(&quot;L&quot;).lstrip(&quot;0x&quot;)</p>
<p>hexpublickey = &quot;04&quot; + y + z</p>
</blockquote>

CC BY-SA 3.0
2017-11-22T20:00:02.423Z
2017-11-22T20:00:02.423Z
2020-06-16T11:10:03.350Z
Mine
<p>If I get a public key of two integers, x and y values what code is necessary to convert them into their hex versions without any additional letters, or numbers?  This is half a Python programming question and half a bitcoin question though I think it is better asked here due to the familiarity with bitcoin requirements.</p>
<p>Pseudo code:</p>
<blockquote>
<p>xpublickey = 20091690549896866803343277351761137627937393619088856147056855893222768847187</p>
<p>ypublickey = 69823032225116710867248379519530157435196049639426167980995931003755153241086</p>
<p>hexpublickey = &quot;04&quot; + hex(xpublickey) + hex(ypublickey)</p>
</blockquote>
<p>I don't know what code is necessary to turn it into (as the above code does not work):</p>
<blockquote>
<p>042C6B7E6DA7633C8F226891CC7FA8E5EC84F8EACC792A46786EFC869A408D29539A5E6F8DE3F71C0014E8EA71691C7B41F45C083A074FEF7AB5C321753BA2B3FE</p>
</blockquote>

<public-key><python><encoding>
What python code is necessary to convert the integers of a bitcoin public key into the proper hex version thereof?
Mine
# What python code is necessary to convert the integers of a bitcoin public key into the proper hex version thereof?

(Asked by: username_0 on 2017-11-22)

If I get a public key of two integers, x and y values what code is necessary to convert them into their hex versions without any additional letters, or numbers? This is half a Python programming question and half a bitcoin question though I think it is better asked here due to the familiarity with bitcoin requirements.

Pseudo code:

> xpublickey = 20091690549896866803343277351761137627937393619088856147056855893222768847187
>
> ypublickey = 69823032225116710867248379519530157435196049639426167980995931003755153241086
>
> hexpublickey = "04" + hex(xpublickey) + hex(ypublickey)

I don't know what code is necessary to turn it into (as the above code does not work):

> 042C6B7E6DA7633C8F226891CC7FA8E5EC84F8EACC792A46786EFC869A408D29539A5E6F8DE3F71C0014E8EA71691C7B41F45C083A074FEF7AB5C321753BA2B3FE

**Tags:** public-key, python, encoding


---

## 1 answers

### Answer by username_0 on 2017-11-22. Score: 0 | Accepted answer

> y = hex(xPublicKey).rstrip("L").lstrip("0x")
>
> z = hex(yPublicKey).rstrip("L").lstrip("0x")
>
> hexpublickey = "04" + y + z


---

