Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,25 +1,25 @@
|
|||
/*REXX program to convert decimal───> binary ───> gray code ───> binary.*/
|
||||
parse arg N .; if N=='' then N=31 /*Not specified? Then use default*/
|
||||
L=max(1,length(strip(x2b(d2x(N)),'L',0))) /*for cell width formatting.*/
|
||||
w=14 /*used for cell width formatting.*/
|
||||
_=center('binary',w,'─') /*2nd and 4th part of the header.*/
|
||||
say center('decimal',w,'─')">" _">" center('gray code',w,'─')">" _ /*hdr*/
|
||||
|
||||
do j=0 to N; b=right(x2b(d2x(j)),L,0) /*handle 0 ──► N.*/
|
||||
g=b2gray(b) /*convert binary to gray code. */
|
||||
a=gray2b(g) /*convert gray code to binary. */
|
||||
say center(j,w+1) center(b,w+1) center(g,w+1) center(a,w+1) /*tell*/
|
||||
/*REXX program converts decimal number ───► binary ───► gray code ───► binary.*/
|
||||
parse arg N . /*get the optional argument from the CL*/
|
||||
if N=='' | N=="," then N=31 /*Not specified? Then use the default.*/
|
||||
L=max(1,length(strip(x2b(d2x(N)),'L',0))) /*find the max binary length of N.*/
|
||||
w=14 /*used for the formatting of cell width*/
|
||||
_=center('binary',w,'─') /*the 2nd and 4th part of the header.*/
|
||||
say center('decimal', w, "─")'►' _"►" center('gray code', w, '─')"►" _
|
||||
/* [+] the output header*/
|
||||
do j=0 to N; b=right(x2b(d2x(j)),L,0) /*process 0 ──► N. */
|
||||
g=b2gray(b) /*convert binary number to gray code. */
|
||||
a=gray2b(g) /*convert the gray code to binary. */
|
||||
say center(j,w+1) center(b,w+1) center(g,w+1) center(a,w+1)
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*───────────────────────────────────B2GRAY subroutine──────────────────*/
|
||||
b2gray: procedure; parse arg x
|
||||
$=left(x,1); do b=2 to length(x)
|
||||
$=$||(substr(x,b-1,1) && substr(x,b,1))
|
||||
end /*b*/ /* && is eXclusive OR*/
|
||||
return $
|
||||
/*───────────────────────────────────GRAY2B subroutine──────────────────*/
|
||||
gray2b: procedure; parse arg x
|
||||
$=left(x,1); do g=2 to length(x)
|
||||
$=$ || (right($,1) && substr(x,g,1))
|
||||
end /*g*/ /* && is eXclusive OR*/
|
||||
return $
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
b2gray: procedure; parse arg x 1 $ 2; do b=2 to length(x)
|
||||
$=$||(substr(x,b-1,1) && substr(x,b,1))
|
||||
end /*b*/
|
||||
return $
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
gray2b: procedure; parse arg x 1 $ 2; do g=2 to length(x)
|
||||
$=$ || (right($,1) && substr(x,g,1))
|
||||
end /*g*/ /* ↑ */
|
||||
/* │ */
|
||||
return $ /*this is an eXclusive OR ►─────────┘ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue