Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
19
Task/Gray-code/Pluto/gray-code.pluto
Normal file
19
Task/Gray-code/Pluto/gray-code.pluto
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
local fmt = require "fmt"
|
||||
|
||||
local function to_gray(n) return n ~ (n >> 1) end
|
||||
|
||||
local function from_gray(g)
|
||||
local b = 0
|
||||
while g != 0 do
|
||||
b ~= g
|
||||
g >>= 1
|
||||
end
|
||||
return b
|
||||
end
|
||||
|
||||
print("decimal binary gray decoded")
|
||||
for b = 0, 31 do
|
||||
fmt.write(" %2d %05d", b, fmt.bin(b))
|
||||
local g = to_gray(b)
|
||||
fmt.print(" %05d %05d", fmt.bin(g), fmt.bin(from_gray(g)))
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue