Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -2,31 +2,23 @@
|
|||
' compile with: fbc -s console
|
||||
|
||||
Function gray2bin(g As UInteger) As UInteger
|
||||
|
||||
Dim As UInteger b = g
|
||||
|
||||
While g
|
||||
g Shr= 1
|
||||
b Xor= g
|
||||
Wend
|
||||
|
||||
Return b
|
||||
|
||||
End Function
|
||||
|
||||
Function bin2gray(b As UInteger) As UInteger
|
||||
|
||||
Return b Xor (b Shr 1)
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As UInteger i
|
||||
|
||||
Print " i binary gray gra2bin"
|
||||
Print String(32,"=")
|
||||
|
||||
For i = 0 To 31
|
||||
Print Using "## --> "; i;
|
||||
print Bin(i,5); " --> ";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
B$ =Gray2Bin$( G$)
|
||||
print B$; " in pure binary."
|
||||
next r
|
||||
|
||||
end
|
||||
|
||||
function Bin2Gray$( bin$) ' Given a binary number as a string, returns Gray code as a string.
|
||||
|
|
|
|||
57
Task/Gray-code/Modula-2/gray-code.mod2
Normal file
57
Task/Gray-code/Modula-2/gray-code.mod2
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
MODULE GrayCode;
|
||||
|
||||
FROM STextIO IMPORT
|
||||
WriteString, WriteLn;
|
||||
FROM SWholeIO IMPORT
|
||||
WriteInt;
|
||||
FROM Conversions IMPORT
|
||||
LongBaseToStr;
|
||||
FROM FormatString IMPORT
|
||||
FormatString; (* for justifying *)
|
||||
|
||||
VAR
|
||||
I, G, D: CARDINAL;
|
||||
Ok: BOOLEAN;
|
||||
BinS, OutBinS: ARRAY[0 .. 5] OF CHAR;
|
||||
|
||||
PROCEDURE Encode(V: CARDINAL): CARDINAL;
|
||||
BEGIN
|
||||
RETURN V BXOR (V SHR 1)
|
||||
END Encode;
|
||||
|
||||
PROCEDURE Decode(V: CARDINAL): CARDINAL;
|
||||
VAR
|
||||
Result: CARDINAL;
|
||||
BEGIN
|
||||
Result := 0;
|
||||
WHILE V > 0 DO
|
||||
Result := Result BXOR V;
|
||||
V := V SHR 1
|
||||
END;
|
||||
RETURN Result
|
||||
END Decode;
|
||||
|
||||
BEGIN
|
||||
WriteString("decimal binary gray decoded");
|
||||
WriteLn;
|
||||
FOR I := 0 TO 31 DO
|
||||
G := Encode(I);
|
||||
D := Decode(G);
|
||||
WriteInt(I, 4);
|
||||
WriteString(" ");
|
||||
Ok := LongBaseToStr(I, 2, BinS);
|
||||
Ok := FormatString("%'05s", OutBinS, BinS);
|
||||
(* Padded with 0; width: 5; type: string *)
|
||||
WriteString(OutBinS);
|
||||
WriteString(" ");
|
||||
Ok := LongBaseToStr(G, 2, BinS);
|
||||
Ok := FormatString("%'05s", OutBinS, BinS);
|
||||
WriteString(OutBinS);
|
||||
WriteString(" ");
|
||||
Ok := LongBaseToStr(D, 2, BinS);
|
||||
Ok := FormatString("%'05s", OutBinS, BinS);
|
||||
WriteString(OutBinS);
|
||||
WriteInt(D, 4);
|
||||
WriteLn;
|
||||
END
|
||||
END GrayCode.
|
||||
Loading…
Add table
Add a link
Reference in a new issue