Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Gray-code/XBasic/gray-code.basic
Normal file
30
Task/Gray-code/XBasic/gray-code.basic
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
' Gray code
|
||||
PROGRAM "graycode"
|
||||
VERSION "0.0001"
|
||||
|
||||
DECLARE FUNCTION Entry()
|
||||
INTERNAL FUNCTION Encode(v&)
|
||||
INTERNAL FUNCTION Decode(v&)
|
||||
|
||||
FUNCTION Entry()
|
||||
PRINT "decimal binary gray decoded"
|
||||
FOR i& = 0 TO 31
|
||||
g& = Encode(i&)
|
||||
d& = Decode(g&)
|
||||
PRINT FORMAT$(" ##", i&); " "; BIN$(i&, 5); " "; BIN$(g&, 5);
|
||||
PRINT " "; BIN$(d&, 5); FORMAT$(" ##", d&)
|
||||
NEXT i&
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Encode(v&)
|
||||
END FUNCTION v& ^ (v& >> 1)
|
||||
|
||||
FUNCTION Decode(v&)
|
||||
result& = 0
|
||||
DO WHILE v& > 0
|
||||
result& = result& ^ v&
|
||||
v& = v& >> 1
|
||||
LOOP
|
||||
END FUNCTION result&
|
||||
|
||||
END PROGRAM
|
||||
Loading…
Add table
Add a link
Reference in a new issue