Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Gray-code/AutoHotkey/gray-code.ahk
Normal file
23
Task/Gray-code/AutoHotkey/gray-code.ahk
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
gray_encode(n){
|
||||
return n ^ (n >> 1)
|
||||
}
|
||||
|
||||
gray_decode(n){
|
||||
p := n
|
||||
while (n >>= 1)
|
||||
p ^= n
|
||||
return p
|
||||
}
|
||||
|
||||
BinString(n){
|
||||
Loop 5
|
||||
If ( n & ( 1 << (A_Index-1) ) )
|
||||
o := "1" . o
|
||||
else o := "0" . o
|
||||
return o
|
||||
}
|
||||
|
||||
Loop 32
|
||||
n:=A_Index-1, out .= n " : " BinString(n) " => " BinString(e:=gray_encode(n))
|
||||
. " => " BinString(gray_decode(e)) " => " BinString(n) "`n"
|
||||
MsgBox % clipboard := out
|
||||
Loading…
Add table
Add a link
Reference in a new issue