Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/CRC-32/Go/crc-32-1.go
Normal file
12
Task/CRC-32/Go/crc-32-1.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := []byte("The quick brown fox jumps over the lazy dog")
|
||||
result := crc32.ChecksumIEEE(s)
|
||||
fmt.Printf("%X\n", result)
|
||||
}
|
||||
31
Task/CRC-32/Go/crc-32-2.go
Normal file
31
Task/CRC-32/Go/crc-32-2.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var table [256]uint32
|
||||
|
||||
func init() {
|
||||
for i := range table {
|
||||
word := uint32(i)
|
||||
for j := 0; j < 8; j++ {
|
||||
if word&1 == 1 {
|
||||
word = (word >> 1) ^ 0xedb88320
|
||||
} else {
|
||||
word >>= 1
|
||||
}
|
||||
}
|
||||
table[i] = word
|
||||
}
|
||||
}
|
||||
|
||||
func crc32(s string) uint32 {
|
||||
crc := ^uint32(0)
|
||||
for i := 0; i < len(s); i++ {
|
||||
crc = table[byte(crc)^s[i]] ^ (crc >> 8)
|
||||
}
|
||||
return ^crc
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("%0x\n", crc32("The quick brown fox jumps over the lazy dog"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue