RosettaCodeData/Task/Variable-length-quantity/REXX/variable-length-quantity.rexx

25 lines
1.6 KiB
Rexx
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
/*REXX program displays (and also tests/verifies) some numbers as octets. */
2015-02-20 00:35:01 -05:00
nums = x2d(200000) x2d(1fffff) 2097172 2097151
#=words(nums)
2017-09-23 10:01:46 +02:00
say ' number hex octet original'
say ' '
2015-02-20 00:35:01 -05:00
ok=1
2017-09-23 10:01:46 +02:00
do j=1 for #; @.j= word(nums,j)
2015-02-20 00:35:01 -05:00
onum.j=octet(@.j)
2017-09-23 10:01:46 +02:00
orig.j= x2d( space(onum.j, 0) )
w=10
say center(@.j, w) center(d2x(@.j), w) center(onum.j, w) center(orig.j, w)
2015-02-20 00:35:01 -05:00
if @.j\==orig.j then ok=0
end /*j*/
say
2017-09-23 10:01:46 +02:00
if ok then say 'All ' # " numbers are OK." /*all of the numbers are good. */
else say "Some numbers are not OK." /*some of the numbers are ¬good. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
octet: procedure; parse arg z,$ /*obtain Z from the passed arguments.*/
x=d2x(z) /*convert Z to a hexadecimal octet. */
do j=length(x) by -2 to 1 /*process the "little" end first. */
$= substr(x, j-1, 2, 0) $ /*pad odd hexadecimal characters with */
end /*j*/ /* ··· a zero on the left. */
return strip($)