Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Gray-code/BASIC/gray-code.basic
Normal file
24
Task/Gray-code/BASIC/gray-code.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
10 DEFINT A-Z
|
||||
20 FOR I=0 TO 31
|
||||
30 N=I:GOSUB 200:E=R:REM Encode
|
||||
40 N=E:GOSUB 300:D=R:REM Decode
|
||||
50 N=I:GOSUB 400:I$=R$:REM Binary format of input
|
||||
60 N=E:GOSUB 400:E$=R$:REM Binary format of encoded value
|
||||
70 N=D:GOSUB 400:D$=R$:REM Binary format of decoded value
|
||||
80 PRINT USING "##: \ \ => \ \ => \ \ => ##";I;I$;E$;D$;D
|
||||
90 NEXT
|
||||
100 END
|
||||
200 REM Gray encode
|
||||
210 R = N XOR N\2
|
||||
220 RETURN
|
||||
300 REM Gray decode
|
||||
310 R = N
|
||||
320 N = N\2
|
||||
330 IF N=0 THEN RETURN
|
||||
340 R = R XOR N
|
||||
350 GOTO 320
|
||||
400 REM Binary format
|
||||
410 R$ = ""
|
||||
420 R$ = CHR$(48+(N AND 1))+R$
|
||||
430 N = N\2
|
||||
440 IF N=0 THEN RETURN ELSE 420
|
||||
Loading…
Add table
Add a link
Reference in a new issue