Monero address prefix creation algorithm

As I read in the monerobook:

uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18;

Monero's main network uses '18' to indicate a primary address (this is why Monero primary addresses begin with a '4,' which is the ASCII representation).

but as I can see the ASCII table, 18 (DEC) is not corespond 4 (ASCII)!

What algorithm can be used to translate numbers in cryptonote_config.h?

18 <-> 4

42 <-> 8

...

It looks like it's not a Base58 conversion either. I have tried this online tool without success.

Primary Addresses: Base58( 0x12 | S0 | V0 | checksum ) = “ 4 ..........” [95 chars]

Sub Addresses: Base58( 0x2A | Si | Vi | checksum ) = “ 8 ..........” [95 chars]

Integrated Addresses: Base58( 0x13 | S0 | V0 | payID | checksum ) = “ 4 ..........” [106 chars]

source (disclaimer: mine): https://www.getmonero.org/library/MoneroAddressesCheatsheet20201206.pdf

I guess the problem you are having w/ Base58 comes from the tools you are using not applying Base58 to strings as Monero does. From https://xmr.llcoins.net/addresstests.html :

[...] 4. As a last step, this 69-byte string is converted to Base58. However, it's not done all at once like a Bitcoin address, but rather in 8-byte blocks. This gives us eight full-sized blocks and one 5-byte block. Eight bytes converts to 11 or less Base58 characters; if a particular block converts to <11 characters, the conversion pads it with "1"s (1 is 0 in Base58). Likewise, the final 5-byte block can convert to 7 or less Base58 digits; the conversion will ensure the result is 7 digits. Due to the conditional padding, the 69-byte string will always convert to 95 Base58 characters (8 * 11 + 7). [...]

• But as I can see in the Base58 table: Base58(0x12) = K (not 4) And Base58(0x2A) = j (not 8) And Base58(0x13) = L (not 4). I'm confused (( Oct 18, 2021 at 16:52
• I have just edited the answer, hoping to give you some hints. I guess for further detail it's better for you to directly refer to Monero source code Oct 19, 2021 at 14:27