Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Gray-code/XPL0/gray-code.xpl0
Normal file
36
Task/Gray-code/XPL0/gray-code.xpl0
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
|
||||
func Gray2Bin(N); \Convert N from Gray code to binary
|
||||
int N;
|
||||
int S;
|
||||
[S:= 1;
|
||||
repeat N:= N>>S | N;
|
||||
S:= S<<1;
|
||||
until S=32;
|
||||
return N;
|
||||
]; \Gray2Bin
|
||||
|
||||
|
||||
func Bin2Gray(N); \Convert N from binary to Gray code
|
||||
int N;
|
||||
return N>>1 | N;
|
||||
|
||||
|
||||
proc BinOut(N); \Output N in binary
|
||||
int N;
|
||||
int R;
|
||||
[R:= N&1;
|
||||
N:= N>>1;
|
||||
if N then BinOut(N);
|
||||
ChOut(0, R+^0);
|
||||
]; \BinOut
|
||||
|
||||
|
||||
int N, G;
|
||||
[for N:= 0 to 31 do
|
||||
[BinOut(N); ChOut(0, 9\tab\);
|
||||
G:= Bin2Gray(N);
|
||||
BinOut(G); ChOut(0, 9\tab\);
|
||||
BinOut(Gray2Bin(G)); CrLf(0);
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue