29 lines
625 B
Plaintext
29 lines
625 B
Plaintext
F to_str(v)
|
||
R ‘[ ’v.map(n -> hex(n).lowercase().zfill(2)).join(‘ ’)‘ ]’
|
||
|
||
F to_seq(UInt64 x)
|
||
V i = 0
|
||
L(ii) (9.<0).step(-1)
|
||
I x [&] (UInt64(127) << ii * 7) != 0
|
||
i = ii
|
||
L.break
|
||
|
||
[Byte] out
|
||
L(j) 0 .. i
|
||
out [+]= ((x >> ((i - j) * 7)) [&] 127) [|] 128
|
||
|
||
out[i] (+)= 128
|
||
R out
|
||
|
||
F from_seq(seq)
|
||
UInt64 r = 0
|
||
|
||
L(b) seq
|
||
r = (r << 7) [|] (b [&] 127)
|
||
|
||
R r
|
||
|
||
L(x) [UInt64(7'F), 40'00, 0, 003F'FFFE, 001F'FFFF, 0020'0000, 3311'A123'4DF3'1413]
|
||
V s = to_seq(x)
|
||
print(‘seq from ’hex(x).lowercase()‘ ’to_str(s)‘ back: ’hex(from_seq(s)).lowercase())
|