25 lines
593 B
Plaintext
25 lines
593 B
Plaintext
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
|