user66581: I would like to calculate the segwit address of a public address.
First step: 
take the compressed public address:
1L88S26C5oyjL1gkXsBeYwHHjvGvCcidr9

do a sha256 on that address:
151de228f6bec7635097f7813786830505d04bf56806f11eb056441fdc917d41

do a ripemd160:
9bbfb2424372d687cf35fd7d1e978f85a11157ca

encode with Base58:
usT1ggHqtEAcGd4ZysWqtxaaQmT

There is something wrong since every segwit address should start with "3". Can someone help me which step it is?
My source of how a segwit address is calculated is: How to get legacy address and private key from Segwit P2SH address? Quote:

You have the private key so you can just derive the address from there. Get the corresponding public key, hash it with SHA256 and then that result with RIPEMD160. Then perform Base58Check Encoding on it.


user51045: Java code doing that was pasted here, but mostly without any explanation, so I'll try to explain.
When I was looking information about it, the best example was found in BIP-49 text. We start from the following line:
// Address derivation
keyhash = HASH160(account0recvPublickKeyHex) = 0x38971f73930f6c141d977ac4fd4a727c854935b3

So we have 20 bytes of public key hash: < keyhash >. If we want to obtain legacy key, we simply prepend < prefixByte > (prefixByte = 0 for BTC main) and get < prefixByte | keyhash > array. Then we should do HASH160(< prefixByte | keyhash >), and take first 4 bytes as checksum. So the resulting address looks like < 0 | keyhash | checksum > - 25 bytes total. It is an address in his hex form. To get a common form we should only base58-encode it.
If we want to obtain a segwit-address, first we want to get < keyhash >. We should decode base58-encoded address to an < addressArray > and check the checksum (that last 4 bytes are equal to HASH160 of first 21). If everything is correct, we should drop first one and last four bytes of < addressArray > to obtain a < keyhash >.
The next step is to get a < scriptSig >, simply prepending 0x0014 bytes to a < keyhash > array:
scriptSig = < 0 < keyhash > > = 0x001438971f73930f6c141d977ac4fd4a727c854935b3

We get segwitBytes hashing < scriptSig >:
segwitBytes = HASH160(scriptSig) = 0x336caa13e08b96080a32b5d818d59b4ab3b36742

And finally, we get an address, prepending p2shHeader (=5 for BTC MainNet, 196 for BTC Testnet) to segwitBytes, and appends their checksum:
// segwitBytes base58check encoded for testnet
address = base58check(p2shHeader | segitBytes) = 2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2 (testnet)

HASH160 is following: first we use SHA256 function to hash and than RIPEMD160 on result. The example implemented in Java can be found for example here (function org.bitcoinj.core.Utils.sha256hash160).

user51948: Firstly, it is very dangerous to convert a public address to a different form and then use it, because the owner of that address will not be expecting payments on other forms, and could result in fund loss. Only use addresses which the recipient has asked you to use.
But there is a difference between a compressed public key and an address. Bitcoin addresses starting with 1 are base58 encoded keyhash with a checksum. To get the key hash which is the ripemd/sha256 hash of the public key, you must decode the base58 and ensure the checksum is correct. Then you simply use the keyhash in the redeem script, you don't need to perform any more hashing on it to form the P2WPKH script. Notice that there is no way to know if an address starting with a 1 used a compressed or uncompressed public key before it's spent, so if you tried to convert one which had an uncompressed key, it would be unspendable, very dangerous as I said earlier.
See here for more details: https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address

66581: <p>I would like to calculate the segwit address of a public address.</p>

<pre><code>First step: 
take the compressed public address:
1L88S26C5oyjL1gkXsBeYwHHjvGvCcidr9

do a sha256 on that address:
151de228f6bec7635097f7813786830505d04bf56806f11eb056441fdc917d41

do a ripemd160:
9bbfb2424372d687cf35fd7d1e978f85a11157ca

encode with Base58:
usT1ggHqtEAcGd4ZysWqtxaaQmT
</code></pre>

<p>There is something wrong since every segwit address should start with "3". <strong>Can someone help me which step it is?</strong></p>

<p>My source of how a segwit address is calculated is: <a href="https://bitcoin.stackexchange.com/questions/63472/how-to-get-legacy-address-and-private-key-from-segwit-p2sh-address">How to get legacy address and private key from Segwit P2SH address?</a> Quote:</p>

<blockquote>
  <p>You have the private key so you can just derive the address from there. Get the corresponding public key, hash it with SHA256 and then that result with RIPEMD160. Then perform Base58Check Encoding on it.</p>
</blockquote>
 51045: <p>Java code doing that was pasted <a href="https://bitcoin.stackexchange.com/a/67029/51045">here</a>, but mostly without any explanation, so I'll try to explain.</p>

<p>When I was looking information about it, the best example was found in <a href="https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki#test-vectors" rel="nofollow noreferrer">BIP-49</a> text. We start from the following line:</p>

<pre><code>// Address derivation
keyhash = HASH160(account0recvPublickKeyHex) = 0x38971f73930f6c141d977ac4fd4a727c854935b3
</code></pre>

<p>So we have 20 bytes of public key hash: &lt; keyhash >. If we want to obtain legacy key, we simply prepend &lt; prefixByte > (prefixByte = 0 for BTC main) and get &lt; prefixByte | keyhash > array. Then we should do HASH160(&lt; prefixByte | keyhash >), and take first 4 bytes as checksum. So the resulting address looks like &lt; 0 | keyhash | checksum > - 25 bytes total. It is an address in his hex form. To get a common form we should only base58-encode it.</p>

<p>If we want to obtain a segwit-address, first we want to get &lt; keyhash >. We should decode base58-encoded address to an &lt; addressArray > and check the checksum (that last 4 bytes are equal to HASH160 of first 21). If everything is correct, we should drop first one and last four bytes of &lt; addressArray > to obtain a &lt; keyhash >.</p>

<p>The next step is to get a &lt; scriptSig >, simply prepending 0x0014 bytes to a &lt; keyhash > array:</p>

<pre><code>scriptSig = &lt; 0 &lt; keyhash &gt; &gt; = 0x001438971f73930f6c141d977ac4fd4a727c854935b3
</code></pre>

<p>We get segwitBytes hashing &lt; scriptSig >:</p>

<pre><code>segwitBytes = HASH160(scriptSig) = 0x336caa13e08b96080a32b5d818d59b4ab3b36742
</code></pre>

<p>And finally, we get an address, prepending p2shHeader (=5 for BTC MainNet, 196 for BTC Testnet) to segwitBytes, and appends their checksum:</p>

<pre><code>// segwitBytes base58check encoded for testnet
address = base58check(p2shHeader | segitBytes) = 2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2 (testnet)
</code></pre>

<p>HASH160 is following: first we use SHA256 function to hash and than RIPEMD160 on result. The example implemented in Java can be found for example <a href="https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/core/Utils.java" rel="nofollow noreferrer">here</a> (function org.bitcoinj.core.Utils.sha256hash160).</p>
 51948: <p>Firstly, it is very dangerous to convert a public address to a different form and then use it, because the owner of that address will not be expecting payments on other forms, and could result in fund loss. Only use addresses which the recipient has asked you to use.</p>

<p>But there is a difference between a compressed public key and an address. Bitcoin addresses starting with <code>1</code> are base58 encoded keyhash with a checksum. To get the key hash which is the ripemd/sha256 hash of the public key, you must decode the base58 and ensure the checksum is correct. Then you simply use the keyhash in the redeem script, you don't need to perform any more hashing on it to form the P2WPKH script. Notice that there is no way to know if an address starting with a 1 used a compressed or uncompressed public key before it's spent, so if you tried to convert one which had an uncompressed key, it would be unspendable, very dangerous as I said earlier.</p>

<p>See here for more details: <a href="https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address" rel="nofollow noreferrer">https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wpkh-address</a></p>
