Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Gray-code/Go/gray-code.go
Normal file
23
Task/Gray-code/Go/gray-code.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func enc(b int) int {
|
||||
return b ^ b>>1
|
||||
}
|
||||
|
||||
func dec(g int) (b int) {
|
||||
for ; g != 0; g >>= 1 {
|
||||
b ^= g
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("decimal binary gray decoded")
|
||||
for b := 0; b < 32; b++ {
|
||||
g := enc(b)
|
||||
d := dec(g)
|
||||
fmt.Printf(" %2d %05b %05b %05b %2d\n", b, b, g, d, d)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue