Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Gray-code/Icon/gray-code.icon
Normal file
18
Task/Gray-code/Icon/gray-code.icon
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
link bitint
|
||||
|
||||
procedure main()
|
||||
every write(right(i := 0 to 10,4),":",right(int2bit(i),10)," -> ",
|
||||
right(g := gEncode(i),10)," -> ",
|
||||
right(b := gDecode(g),10)," -> ",
|
||||
right(bit2int(b),10))
|
||||
end
|
||||
|
||||
procedure gEncode(b)
|
||||
return int2bit(ixor(b, ishift(b,-1)))
|
||||
end
|
||||
|
||||
procedure gDecode(g)
|
||||
b := g[1]
|
||||
every i := 2 to *g do b ||:= if g[i] == b[i-1] then "0" else "1"
|
||||
return b
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue