RosettaCodeData/Task/Variable-length-quantity/PL-I/variable-length-quantity.pli

29 lines
707 B
Plaintext

test: procedure options(main);
declare s character (20) varying;
declare c character (1);
declare v fixed binary (31);
declare (i, k) fixed binary;
get edit (s) (L);
s = trim (s);
v = 0;
do i = 1 to length(s);
c = substr(s, i, 1);
k = index('0123456789abcdef', c);
if k > 0 then v = v*16 + k - 1;
end;
put skip data (s, v);
/* Convert back to hex */
declare hex character(16) initial ('0123456789abcdef');
declare hs character (20) initial ('');
declare d fixed binary;
do i = length(hs) to 1 by -1 until (v = 0);
d = mod(v, 16) + 1;
substr(hs, i, 1) = substr(hex, d, 1);
v = v/16;
end;
put skip list (hs);
end test;