Skip to content

Instantly share code, notes, and snippets.

@cdcs
Created October 19, 2016 08:41
Show Gist options
  • Save cdcs/60e6ba2e49457fb11e8d993f5a15130f to your computer and use it in GitHub Desktop.
Save cdcs/60e6ba2e49457fb11e8d993f5a15130f to your computer and use it in GitHub Desktop.
func main() {
s1 := []byte("this is a test")
s2 := []byte("wokka wokka!!!")
fmt.Println("Hello, playground")
fmt.Println(bhamming(0xFF, 0))
fmt.Println(hamming(s1, s2))
}
func hamming(a, b []byte) int {
var count int = 0
if len(a) != len(b) {
return 0
}
for i, _ := range a {
count = count + bhamming(a[i], b[i])
}
return count
}
func bhamming(a, b byte) int {
var count int = 0
var i uint
c := a ^ b
for i = 0; i < 8; i++ {
if ((c >> i) & 0x01) == 1 {
count = count + 1
}
}
return count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment