<p>PSBT uses <a href="https://en.wikipedia.org/wiki/Base64" rel="nofollow noreferrer">Base64</a> encoding. As every Base64 character has <em>64 = 2<sup>6</sup></em> possibilities, they can store 6 bits of information. The <code>ConvertBits</code> function you link to takes input bytes (which consist of 8 bits each), and rearranges them into groups of 6 bits, which are then mapped to the Base64 character set.</p>
<p><code>ConvertBits&lt;A,B&gt;</code> is not converting from base-<em>A</em> to base-<em>B</em>; it is converting from base-<em>2<sup>A</sup></em> to base-<em>2<sup>B</sup></em>.</p>

CC BY-SA 4.0
2020-11-11T23:19:07.297Z
2020-11-11T23:45:10.873Z
2020-11-11T23:45:10.873Z
Pieter Wuille
<p>I'm currently working on PSBT and I try to understand all the part of the original implementation.</p>
<p>Dealing with base64 PSBT encoding: it seems that we convert the buffer from a base 8 to a base 6 using the <a href="https://www.github.com/bitcoin/bitcoin/tree/master/src%2Futil%2Fstrencodings.h" rel="nofollow noreferrer">convertBytes</a> function.</p>
<p>Is someone that could explain me the aim of this conversion ?</p>

<bitcoin-core><bip174-psbt>
PSBT encoding : what's the aim of convertBytes function?
Louis Singer
# PSBT encoding : what's the aim of convertBytes function?

(Asked by: username_0 on 2020-11-10)

I'm currently working on PSBT and I try to understand all the part of the original implementation.

Dealing with base64 PSBT encoding: it seems that we convert the buffer from a base 8 to a base 6 using the [convertBytes](https://www.github.com/bitcoin/bitcoin/tree/master/src%2Futil%2Fstrencodings.h) function.

Is someone that could explain me the aim of this conversion ?

**Tags:** bitcoin-core, bip174-psbt


---

## 1 answers

### Answer by username_1 on 2020-11-11. Score: 1 | Accepted answer

PSBT uses [Base64](https://en.wikipedia.org/wiki/Base64) encoding. As every Base64 character has *64 = 26* possibilities, they can store 6 bits of information. The `ConvertBits` function you link to takes input bytes (which consist of 8 bits each), and rearranges them into groups of 6 bits, which are then mapped to the Base64 character set.

`ConvertBits` is not converting from base-*A* to base-*B*; it is converting from base-*2A* to base-*2B*.


---

