<p>Assuming the key is the posted  compressed WIF <code>KwDiBf89QgGbjEmUcXPRwPuKPFnFECvJkvovGNiyjaujMCrQXy98</code>:   </p>

<ol>
<li>Decode the key you have using the encoder used (in this case <a href="https://en.bitcoin.it/wiki/Base58Check_encoding" rel="noreferrer">base-58</a>)<br>
<code>80-00000000000000000006f5d7d806edef2e1110b0b243f9a90c2aaaaaaaaaaaaa-01-098dbf37</code></li>
<li>Remove the <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="noreferrer">extra bytes</a> (version byte, compressed byte if present, checksum)<br>
<code>00000000000000000006f5d7d806edef2e1110b0b243f9a90c2aaaaaaaaaaaaa</code></li>
<li>Take the remaining bytes (in this case it must be 32 bytes) and convert it to an integer assuming it is positive and in <a href="https://en.wikipedia.org/wiki/Endianness" rel="noreferrer">big-endian</a> (most significant value is stored first).<br>
<code>666666666666666666666666666666666666666666666666666666</code></li>
</ol>

CC BY-SA 4.0
2019-09-04T03:36:58.410Z
@The Gripmaster you should also add that entering "private key" in a website is not a good idea.
Coding Enthusiast
CC BY-SA 4.0
2019-08-25T04:26:10.977Z
2019-08-25T04:26:10.977Z
Coding Enthusiast
<p>I have a random private key (compressed or uncompressed) <code>5HpHagT65TZzG1QDbnQCzdudnpknN7nA1SLEt4ZcxsH2SV92yqt</code> or <code>KwDiBf89QgGbjEmUcXPRwPuKPFnFECvJkvovGNiyjaujMCrQXy98</code>. How do I convert this private key back to an integer?</p>

<private-key><private-key-format>
Convert private key to integer
GMaster
# Convert private key to integer

(Asked by: username_0 on 2019-08-25)

I have a random private key (compressed or uncompressed) `5HpHagT65TZzG1QDbnQCzdudnpknN7nA1SLEt4ZcxsH2SV92yqt` or `KwDiBf89QgGbjEmUcXPRwPuKPFnFECvJkvovGNiyjaujMCrQXy98`. How do I convert this private key back to an integer?

**Tags:** private-key, private-key-format


---

## 1 answers

### Answer by username_1 on 2019-08-25. Score: 5 | Accepted answer

Assuming the key is the posted compressed WIF `KwDiBf89QgGbjEmUcXPRwPuKPFnFECvJkvovGNiyjaujMCrQXy98`:

1. Decode the key you have using the encoder used (in this case [base-58](https://en.bitcoin.it/wiki/Base58Check_encoding))  
   `80-00000000000000000006f5d7d806edef2e1110b0b243f9a90c2aaaaaaaaaaaaa-01-098dbf37`
2. Remove the [extra bytes](https://en.bitcoin.it/wiki/Wallet_import_format) (version byte, compressed byte if present, checksum)  
   `00000000000000000006f5d7d806edef2e1110b0b243f9a90c2aaaaaaaaaaaaa`
3. Take the remaining bytes (in this case it must be 32 bytes) and convert it to an integer assuming it is positive and in [big-endian](https://en.wikipedia.org/wiki/Endianness) (most significant value is stored first).  
   `666666666666666666666666666666666666666666666666666666`

> **Comments:**
> **username_1**: @The Gripmaster you should also add that entering "private key" in a website is not a good idea.  

---

