Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Gray-code/M2000-Interpreter/gray-code.m2000
Normal file
29
Task/Gray-code/M2000-Interpreter/gray-code.m2000
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Module Code32 (&code(), &decode()){
|
||||
Const d$="{0::-2} {1:-6} {2:-6} {3:-6} {4::-2}"
|
||||
For i=0 to 32
|
||||
g=code(i)
|
||||
b=decode(g)
|
||||
Print format$(d$, i, @bin$(i), @bin$(g), @bin$(b), b)
|
||||
Next
|
||||
// static function
|
||||
Function bin$(a)
|
||||
a$=""
|
||||
Do n= a mod 2 : a$=if$(n=1->"1", "0")+a$ : a|div 2 : Until a==0
|
||||
=a$
|
||||
End Function
|
||||
}
|
||||
Module GrayCode {
|
||||
Module doit (&a(), &b()) { }
|
||||
Function GrayEncode(a) {
|
||||
=binary.xor(a, binary.shift(a,-1))
|
||||
}
|
||||
Function GrayDecode(a) {
|
||||
b=0
|
||||
Do b=binary.xor(a, b) : a=binary.shift(a,-1) : Until a==0
|
||||
=b
|
||||
}
|
||||
// pass 2 functions to Code32
|
||||
doit &GrayEncode(), &GrayDecode()
|
||||
}
|
||||
// pass Code32 to GrayCode in place of doit
|
||||
GrayCode ; doit as Code32
|
||||
Loading…
Add table
Add a link
Reference in a new issue