Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
6
Task/Gray-code/Scala/gray-code-1.scala
Normal file
6
Task/Gray-code/Scala/gray-code-1.scala
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def encode(n: Int) = (n ^ (n >>> 1)).toBinaryString
|
||||
def decode(s: String) = Integer.parseInt( s.scanLeft(0)(_ ^ _.asDigit).tail.mkString , 2)
|
||||
|
||||
println("decimal binary gray decoded")
|
||||
for (i <- 0 to 31; g = encode(i))
|
||||
println("%7d %6s %5s %7s".format(i, i.toBinaryString, g, decode(g)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue