<p>The following Python code does the thing. Iterating from right, those 7-bit UINTs should be cleared of the oldest bit, then shifted right by their right-index.</p>
<pre><code>def popvarlenuint(data):
    _intbytes = []
    while data:
        b = data[0]
        data = data[1:]
        _intbytes.append(b &amp; 0x7F)
        if b &amp; 0x80 == 0:
            break
    val = 0
    for idx, b in enumerate(reversed(_intbytes)):
        val = val | (b &lt;&lt; (8 * idx) - idx)
    return val, data
</code></pre>

CC BY-SA 4.0
2021-12-28T22:05:06.293Z
2021-12-28T22:05:06.293Z
emesik
<p>I'm writing an address parser based on <a href="https://github.com/cardano-foundation/CIPs/blob/master/CIP-0019/README.md" rel="nofollow noreferrer">CIP-0019</a>. The part I have problems with is the <code>POINTER</code> data structure which consists of three <em>&quot;variable-length positive numbers&quot;</em>. The format of the number is described as:</p>
<pre><code>VARIABLE-LENGTH-UINT = (%b1 | UINT7 | VARIABLE-LENGTH-UINT) 
                     / (%b0 | UINT7)
</code></pre>
<p>So, IIUC, I should read bytes while their oldest bit is <code>1</code>, then read one byte more. I should also clear the oldest bits from them. Then I finish with a bunch of <code>UINT7</code>.</p>
<p>How should I convert them to the final integer value?</p>

<address>
How to decode a pointer from Shelley address?
# How to decode a pointer from Shelley address?

(Asked by: username_0 on 2021-12-26)

I'm writing an address parser based on CIP-0019. The part I have problems with is the POINTER data structure which consists of three "variable-length positive numbers". The format of the number is described as:
VARIABLE-LENGTH-UINT = (%b1 | UINT7 | VARIABLE-LENGTH-UINT) 
                     / (%b0 | UINT7)

So, IIUC, I should read bytes while their oldest bit is 1, then read one byte more. I should also clear the oldest bits from them. Then I finish with a bunch of UINT7.
How should I convert them to the final integer value?

**Tags:** address

---

## 1 answers

### Answer by username_0 on 2021-12-28. Score: 0

The following Python code does the thing. Iterating from right, those 7-bit UINTs should be cleared of the oldest bit, then shifted right by their right-index.
def popvarlenuint(data):
    _intbytes = []
    while data:
        b = data[0]
        data = data[1:]
        _intbytes.append(b & 0x7F)
        if b & 0x80 == 0:
            break
    val = 0
    for idx, b in enumerate(reversed(_intbytes)):
        val = val | (b << (8 * idx) - idx)
    return val, data


---

