Variable-length quantity: Difference between revisions

m
m (→‎{{header|zkl}}: reformat)
Line 1,718:
{{trans|C}}
<lang zkl>fcn to_seq(x){ //--> list of ints
reg z := (x.log2()/7);
(0).pump(z+1,List,'wrap(j){
x.shiftRight((z-j)*7).bitAnd(0x7f).bitOr((j!=z) and 0x80 or 0)});
});
}
 
fcn from_seq(in){ in.reduce(fcn(p,n){ p.shiftLeft(7).bitOr(n.bitAnd(0x7f)) },0) }</lang>
<lang zkl>ns:=T(0x7f, 0x4000, 0, 0x3ffffe, 0x1fffff, 0x200000, 0x3311a1234df31413);
 
ms:=ns.apply(to_seq);
 
ns.zipWith(fcn{"%8,x --> %s --> %,x".fmt(vm.arglist.xplode()).println()},
ms.apply("apply","%,x".fmt),
Anonymous user