Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
18
Task/Gray-code/PascalABC.NET/gray-code.pas
Normal file
18
Task/Gray-code/PascalABC.NET/gray-code.pas
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
uses School;
|
||||
|
||||
function GrayEncode(n: longword): longword := n xor (n shr 1);
|
||||
|
||||
function GrayDecode(n: longword): longword;
|
||||
begin
|
||||
Result := 0;
|
||||
while n > 0 do
|
||||
begin
|
||||
Result := Result xor n;
|
||||
n := n shr 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
for var i := 0 to 31 do
|
||||
Writeln($'{i,-7} {Bin(i),-7} {Bin(grayEncode(i)),-7} {grayDecode(grayEncode(i)),-7}');
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue