Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Gray-code/Amazing-Hopper/gray-code.hopper
Normal file
31
Task/Gray-code/Amazing-Hopper/gray-code.hopper
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#proto GrayEncode(_X_)
|
||||
#synon _GrayEncode *getGrayEncode
|
||||
#proto GrayDecode(_X_)
|
||||
#synon _GrayDecode *getGrayDecode
|
||||
|
||||
#include <hbasic.h>
|
||||
|
||||
Begin
|
||||
Gray=0
|
||||
SizeBin(4) // size 5 bits: 0->4
|
||||
Take (" # BINARY GRAY DECODE\n")
|
||||
Take ("------------------------------\n"), and Print It
|
||||
For Up( i := 0, 31, 1)
|
||||
Print( LPad$(" ",2,Str$(i))," => ", Bin$(i)," => ")
|
||||
get Gray Encode(i) and Copy to (Gray), get Binary; then Take(" => ")
|
||||
now get Gray Decode( Gray ), get Binary, and Print It with a Newl
|
||||
Next
|
||||
End
|
||||
|
||||
Subrutines
|
||||
|
||||
Gray Encode(n)
|
||||
Return (XorBit( RShift(1,n), n ))
|
||||
|
||||
Gray Decode(n)
|
||||
p = n
|
||||
While ( n )
|
||||
n >>= 1
|
||||
p != n
|
||||
Wend
|
||||
Return (p)
|
||||
Loading…
Add table
Add a link
Reference in a new issue