Created
October 19, 2016 08:41
-
-
Save cdcs/60e6ba2e49457fb11e8d993f5a15130f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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